0

I am trying to identify whether a certain png file is placed besides another png file, and if so there will be an alert.

Problem is alert will show up as soon as webpage is loaded.

The code I am using for the png files are:

<div id="container" style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%)">
    <div id="donkey">
        <img src="images/donkey.png">
    </div>
    <div id="tail">
        <img src="images/donkeytail.png">
    </div>
</div>

and the jquery code is:

<script>
    $(function() {
        $( "#tail" ).draggable();
    });
    if($("#tail").css({top: 382, left: 810, position:'absolute'})){
        alert ('You win');
    }
</script>

I used a chrome extension to find those coordinates, which are the coordinates exactly where the tail should be placed.

I am not sure if I am doing this the right way and I'd appreciate any help.

Thanks!

1 Answer 1

0

You can use position method of jquery as

if($("#tail").position().top == 382 && $("#tail").position().left == 810)){
        alert ('You win');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.