Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  95] [ 7]  / answers: 1 / hits: 52941  / 13 Years ago, tue, january 31, 2012, 12:00:00

Assume I have the following HTML -



<DIV id=ParentDiv>
<DIV id=SubDiv1></DIV>
<DIV id=SubDiv2>
<INPUT id=input>
</DIV>
</DIV>


To access the input element using jquery, it would be simply $(#input). What I'm trying to do is access it, assuming I only know the ID of the top level div.



Currently I have



$($($(#ParentDiv).children()[1]).children()[0])


Which does seem to work. Is there a cleaner way of writing this, or is the way I am doing it ok?


More From » jquery

 Answers
8

You would just perform a .find() implicitly or explicitly:



$('#ParentDiv input');  // implicitly

$('#ParentDiv').find('input'); // explicitly


Reference: .find()


[#87716] Sunday, January 29, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alorac

Total Points: 262
Total Questions: 82
Total Answers: 97

Location: Libya
Member since Mon, Dec 7, 2020
3 Years ago
alorac questions
Sat, Oct 10, 20, 00:00, 4 Years ago
Tue, Sep 22, 20, 00:00, 4 Years ago
Wed, Jul 1, 20, 00:00, 4 Years ago
Wed, Jun 3, 20, 00:00, 4 Years ago
Sun, May 17, 20, 00:00, 4 Years ago
;