简体   繁体   English

在jQuery中找到父母的孩子

[英]Find Children In Parent in Jquery

I am working with Visual Studio 2010 C# and jQuery . 我正在使用Visual Studio 2010 C#jQuery On my web form I have one main div( divMain ). 在我的Web表单上,我有一个主div( divMain )。 Inside this div some children are created dynamically namely divValue0,divValue1....divValuen . 在此div内,动态创建了一些子divValue0,divValue1....divValuendivValue0,divValue1....divValuen I want to access each div whose id starts with divValue . 我想访问其iddivValue开头的每个div。

Assuming I've understood your question correctly, you want to find all div elements whose id starts with "divValue" that are children of divMain . 假设我已经正确理解了您的问题,那么您想查找所有id都是divMain子元素的,以“ divValue”开头的div元素。 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". 它使用“ attribute starts-with ”选择器来匹配id值以“ 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. children方法返回所选元素的所有子级,但是如果您想要后代在DOM的更下层,则必须使用find

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM