フォーム入力でフォーカスが外れた時に発火するエラーメッセージ表示のプログラムを作りたいです。
inputの直後に空のdivタグを入れておき、それにメッセージを入れるなどの処理をするつもりなのですが、divタグが.next()でうまく指定できません。
inputに使えなかったりするんでしょうか?
ご回答宜しくお願いします。
consoleには、
S.fn.init [prevObject: S.fn.init(1)]
length: 0
prevObject: S.fn.init [input#Cnt2.form__area.js-cntitem.js-cnttext.js-require]
[[Prototype]]: Object(0)
と出ます。
.next()外すとinputは取得で来ていると思います。
html
1<p class="form__tag">お名前</p> 2<p> 3 <input id="Cnt2" class="form__area js-CntItem js-CntText js-Require" name="entry.1841666190" type="text" placeholder="例)山田太郎"> 4 <div class="errorBox"></div> 5</p>
javascript
1$('.js-CntItem').blur(function () { 2 // 必須(js-Require)に中身が入っていない場合 3 if ($(this).hasClass('js-Require') && $(this).val() == '') { 4 console.log($(this).next()); 5 $(this).next('.errorBox').html('<p class="error-message">必須項目が入力されていません。</p>') 6 } 7 })

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/22 09:02