-3

他の要素の ID で HTML 要素を取得する必要があります。しかし、親要素を介して行う必要があります。

<div id="one" class="a">html value 1
    <div id="two" class="a">html value 2</div> 
</div>
4

4 に答える 4

2
$('#one div:first').attr('id');
于 2013-01-07T10:26:59.037 に答える
1

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..
于 2013-01-07T10:39:03.280 に答える
0

を使用$('#one #two')すると、jquery でラップされた要素が返されますdiv#two
:id一意である必要があります

于 2013-01-07T10:33:46.483 に答える
0

これを試して....

$('#one > div').attr('id');
于 2013-01-07T10:28:40.573 に答える