2

I need to use jQuery (or anything) that clicked specific coordinates after button is clicked. specific coordinates

Here is my code, but It not working. As you see in picture in these coordinates (10,15) is red button, which should be clicked.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script>
    $(function(){
        $("#filter").click(function(e){
             //If I add alert here It successfully print message.
             var e = new jQuery.Event("click");
                e.pageX = 10;
                e.pageY = 15;
                $("#elem").trigger(e);
        });
    });
    </script>

<input type="button" id="filter" name="filter" value="Filter" />

I've read this, but wont help: Triggering a JavaScript click() event at specific coordinates

Community
  • 1
  • 1

1 Answers1

1

What you are basically trying to do is to trigger click on some other button , based on the click of this button.

you should try something like this

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script>
    $(function(){
        $("#filter").click(function(e){
           $('#redbuttonID').trigger('click');
        });
    });
    </script>

the rest of the code for setting e.pageX etc is not required

see this: http://jsfiddle.net/J9v6z/

EDIT:

you can get an element using x/y co-ordinates - so you could fire a click event on the element at x/y.

$(document.elementFromPoint(x, y)).click();

or

$(document.elementFromPoint(x, y)).trigger('click');

https://developer.mozilla.org/En/DOM:document.elementFromPoint

EDIT: updated fiddle with your requirement:

http://jsfiddle.net/J9v6z/1/

gaurav5430
  • 12,934
  • 6
  • 54
  • 111
  • Thank you for answer, here `$(document.elementFromPoint(x, y)).trigger('click');` instead x, y I need to enter number of coordinates? –  Dec 24 '13 at 22:43
  • @RimantėBaltiejūtė see the last edit, it addresses your requirement exactly – gaurav5430 Dec 24 '13 at 23:06
  • @RimantėBaltiejūtė did you check the link at the last. i have a working code there http://jsfiddle.net/J9v6z/1/ – gaurav5430 Dec 24 '13 at 23:12
  • I'm trying to click Facebook button by this way, maybe that's why It not working –  Dec 24 '13 at 23:26
  • are you sure you have got the correct coordinates? does the fiddle work well for you? – gaurav5430 Dec 24 '13 at 23:27
  • Yes, fiddle working and coordinates are correct, so that problem is because It can't click Facebook like button I think. –  Dec 24 '13 at 23:32