0

I want to select all the child elements that has a class name begins with a certain string, or at least know if that parent has this kind of children:

HTML:

<div class="myParent">
    <div class="good_child_1">
    </div>
    <div class="bad_child_1">
    </div>
    <div class="good_child_2">
    </div>
    <div class="bad_child_2">
    </div>
    <div class="very_bad_child_23452345">
    </div>
</div>

i want a JQuery code to select all children that start with "good_child", code should be something like this:

JS:

var all_good_childs = $(".myParent").find('[class^="good_child"]');
if (!all_good_childs.length)
{
    //do something  
}

but it didn't work, any suggestions?

ZORRO_BLANCO
  • 849
  • 13
  • 25

1 Answers1

0
$(function() {    
    console.log($("div[class^='good_child']"));
});
xlm
  • 6,854
  • 14
  • 53
  • 55
funcoding
  • 741
  • 6
  • 11
  • @ZORRO_BLANCO this will do it! – funcoding Mar 30 '17 at 15:30
  • I all ready know this code, but it won't work for me, i have a certain parent that should have a certain children...in your code it will select all elements in the page that start with "good_child", but this is not my case – ZORRO_BLANCO Mar 30 '17 at 15:33