views:

70

answers:

5
<div id="dad">
     <img id="mum">
     <input>
</div>

With jQuery, how could i get access to the input element, get is value or set it for example? I can't work out how to access something on the same level.. and i dont want to be using ID's, just parent/child nodes so i can use the code for loads of dad div's

Thanks!

+1  A: 

$(this).parent().children() ?

Zed
when i upvoted you it was parent().children() siblings won't give the same output :)
Sinan Y.
Reverted. Anything for upvotes :)
Zed
+1  A: 
var myEl = $("#dad").children(":input");
code_burgar
Thanks!Although i modified to this........$(this).parent("div").children("input").val();......THANKS!
tarnfeld
You are welcome
code_burgar
A: 

Try this, to find the first child input element:

jQuery("div").find("input:first")
Justin Ethier
A: 

If i understand question, you would like achieve input from mum leve? So try $("#mum ~ input")...

BTW, great site to search jquery function by category http://visualjquery.com/ +nice example.

Rin
+1  A: 

an addition to Zed,

$(this).parent().children('input');

if you give a name to your input field then you can easily select throughout the others,

$(this).parent().children('input[name=my_input]');

then you can give any value as:

$(this).parent().children('input[name=my_input]').val('any value');

Sinan.

Sinan Y.
Thanks :) got there before you commented :(
tarnfeld