0

I have a problem that want to solve it with jQuery.

I have some div with id's "div1,div2,...". In each div I have an input with name pattern.

For example like this

<div id="div1">
  <table>....</table>
  <div>....</div>
  <input name="pattern" value="nothing" />
</div>

I want to get this input for "div1". I can get div1 with $('#div1'). now I want to search only in children of div1. How can I do it with jQuery?

2 Answers 2

1
 $("#div1 input")

or

 $("#div1 input[name=pattern]") // more than 1 input?

or

$("#div1 > input") // only direct child

and so on.

This implies you have to target precisely the div1. A more general approach depends on what you do with the other divs.

Sign up to request clarification or add additional context in comments.

Comments

0

try $('#div1').children('input');

3 Comments

If you want to do this for all the divs it doesn't work. Then you should add a class to each div e.g. class="divs". Then pull .divs through an $(".divs input").each(function(){
@Martin OP wrote "I want to search only in children of div1" If want to select element which have a div parent and their name attribute is pattern then can try $('div input[name=pattern]')
@Martin The general approach depends very much on what the OP wants to do. Your suggestion is correct, but the OP mentioned only div1, maybe if he gives us more info...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.