V.B
V.B

Reputation: 1211

Find Children In Parent in Jquery

I am working with Visual Studio 2010 C# and jQuery. On my web form I have one main div(divMain). Inside this div some children are created dynamically namely divValue0,divValue1....divValuen. I want to access each div whose id starts with divValue.

Upvotes: 0

Views: 1068

Answers (1)

James Allardice
James Allardice

Reputation: 165941

Assuming I've understood your question correctly, you want to find all div elements whose id starts with "divValue" that are children of divMain. If that's right then something like this should work:

var yourDivs = $("#divMain").children("div[id^='divValue']");

It uses an "attribute starts-with" selector to match any element with an id value starting with "divValue". The children method returns all of the children of the selected element, but if you wanted descendants further down the DOM, you'll have to use find instead.

Upvotes: 5

Related Questions