开发者

How to find input tag od div 1?

if we have di开发者_如何学JAVAv like this

<div id="1">
    <input type="text" />
    <div id="2"></div>
</div>
<div id="3">
    <div id="4">
        <input type="text"  />
    </div>
</div>

now if i want to jump from div of id=4 to input tag of <div id="1"> using parent child relationship how can i jump to that particular input tag. Please help

Thanks..


$('#4').parent().prev().children('input:first')

Of course this assumes that div#1 is always the previous sibling of div#3, like you have in the example.


document.getElementById("4").childNodes[0].

Though if you are using jquery it would be something like:

$("#4").children(":input")


IDs can't start with a number, so I change your code to:

<div id="id1">
  <input type="text" />
  <div id="id2"></div>
</div>
<div id="id3">
  <div id="id4">
    <input type="text"  />
  </div>
</div>

So, that makes it:

$("#id4").parents("body").children("div:first").children("input")

Another, shorter version:

$("#id4").parents("body").find('input')

Or the fast way:

$("input:first")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜