Search code examples
jqueryhtmlclickposition

How to Use JQuery to .Click() X Pixels Away From Certain Div


I am using JQuery to click on a certain Div (.button) using the following code:

$(document).ready(function() {
    $('.create-pdf').click(function(e) {  
        $(".button").click();
        //Example: $(".button").position(x, 10px, y, 10px).click();
    });
});

After ".button" is clicked, I want JQuery to click again, but 10px to the right and 10px underneath the ".button" div.

Is there any code for this?


Solution

  • Does this work in your case ?

     var x = $(".button").offset();
      var xcoordinate = x.left;
      var ycoordinate = x.top;
      xcoordinate = xcoordinate +10;
      ycoordinate = ycoordinate +10;
      document.elementFromPoint(xcoordinate , ycoordinate ).click();
    

    What is there at 10px to the right and 10px underneath the .button div? Is there any element? You can also give the class to that element and click using jQuery