I have a function that checks if the img tag is inside a picture element with the "colorbox" class, and if so, add some additional styles to some elements. However, the function still works, even if there are no images in the color image, and I donβt know why.
My jQuery looks like
jQuery(document).ready(function($){ if ($(".colorbox").has("img")) { ~code here~ } }
And here is the colorbox figure, clearly without the img element ...
<figure class="colorbox"> <ficaption> <h2></h2> <p></p> <p></p> </figcaption> </figure>
So why will jQuery collect an element that does not exist?
javascript jquery html
Myles malloy
source share