I have to select elements which contains id attribute and class attribute having ‘child-of-‘ value and loop through the elements returned by the selector.
So far i could write:
$('.child-of-').each(function(){
...
});
This selects all the elements having class of child-of- including elements which does not have id also.
There are elements which has that class but does not have any id attribute.
so How can i select elements which has ‘id’ attribute and id has some value and also has class of child-of-. ?
For example
<div id="any1" class="child-of-"></div>
<div id="any2" class="child-of-"></div>
<div class="child-of-"></div>
Only the div having id attribute must be selected. ie the first two divs in the example. the third does not have id attribute value and hence should not be selected
You can use
attribute selector.Fiddle
If your classes starts with
child-of-you can useattribute starts withselector: