I’m doing a drag and drop using jquery of a picture to a target div.
I have a button that calls a function that should check that the image is inside the div, but I can not get it to work correctly.
I’m trying to do as follows:
<script>
....
$( '#check' ).click(function(){
if($("#droptarget:has(img.img1)")){
alert("yes");
}else{
alert("no");
}
});
</script>
<img id="img1" class="img1" src="image.png">
<div id="droptarget"></div>
<a href="javascript:" id="check">check</a>
What’s wrong in my code?
EDIT: always enters on the first condition doing the alert(“yes”) without the image inside the div
The
$()always a jQuery object which makes it truthy, tryThis checks to see if there are any matches to the selector
#droptarget:has(img.img1)