<div id="ChosenCategory" class="chosen">
   <div class="cat_ch" name="1">
   <div class="cat_ch" name="2">
   <div class="cat_ch" name="3">
   <div class="cat_ch" name="5">
   <div class="clear"> </div>
</div>
I want to loop though div.cat_ch How?
This one fails:
    $("div").each(function () {
       alert("FW");
       alert($(this).attr("name").val());
    });
                $('#ChosenCategory').children('.cat_ch').each(function() {
});
Or
$('#ChosenCategory > .cat_ch').each(function() {
});
JQuery's .children method and css3 child selector > will return only the direct children that match the selector, class .cat_ch in the example.
If you want to search deeper in the DOM tree, that is, include nested elements, use .find or omit the child selector:
$('#ChosenCategory').find('.cat_ch').each( function(){} )
Or
$('#ChosenCategory .cat_ch').each( function(){} )
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With