他の要素の ID で HTML 要素を取得する必要があります。しかし、親要素を介して行う必要があります。
<div id="one" class="a">html value 1
<div id="two" class="a">html value 2</div>
</div>
他の要素の ID で HTML 要素を取得する必要があります。しかし、親要素を介して行う必要があります。
<div id="one" class="a">html value 1
<div id="two" class="a">html value 2</div>
</div>
$('#one div:first').attr('id');
ID は常に一意である必要があります..同じ ID を持つ 2 つの html 要素は無効です..ID をクラスに置き換えて、クラス セレクタを使用できます..
HTML
<div id="one" class="a">html value 1
<div class="a two">html value 2</div>
<div class="a three">html value 3</div>
<div class="a four">html value 4</div>
....
</div>
Jクエリ
$('#one.two').text(); //to get the text inside the element having class as two , gives(html value 2) here..
を使用$('#one #two')
すると、jquery でラップされた要素が返されますdiv#two
。
注:id
一意である必要があります
これを試して....
$('#one > div').attr('id');