Whenever i click on span i want to detect whether i conatins img tag or tag.
How can i do this.
<span class="scorecount" id="6" onclick="javascript:changethevalue(this)">
<img src="images/lock.png" width="25px" height="25px">
</span>
<span class="scorecount" id="6" onclick="javascript:changethevalue(this)">
4
</span>
function changethevalue(object) {
console.log($(object).children('img'));
}
output is when i click on img
[img, prevObject: jQuery.fn.jQuery.init[1], context: span#4.scorecount, selector: “img”, constructor: function, init: function…]
on 4 it is
[prevObject: jQuery.fn.jQuery.init[1], context: span#2.scorecount, selector: “img”, constructor: function, init: function…]
You can use has(), if the
lengthis zero then it means that there is no img tag in descendants ofobject.