Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
入力が含まれているdivのIDを取得する必要があります。次に例を示します。
<div id="example"> <label for="i1">Label1</label> <input id="i1" name="i1" type="text"/> </div>
私は私を助けることができると思います!
:has()セレクターを試すことができます:
:has()
$('div:has("input")').attr('id')
デモ
$('input').on('click', function(){ alert($(this).parent().attr('id')); });
つまり:
$("div:has('input')").attr("id");
または
$("div").has('input').attr("id");