How to trigger a click event on specific x and y position of a div?
$(function() {
$('.rating').on('page:click', function(e) {
var coords = "X coords: " + e.clientX + ", Y coords: " + e.clientY,
aim = document.elementFromPoint(e.clientX, e.clientY);
$(aim).click();
console.log(aim);
$('#status').text(coords);
});
var action = $.Event('page:click', {clientX: 1043, clientY: 70});
$('.rating').trigger(action);
});
How to simulate a click by using x,y coordinates in JavaScript?
You can dispatch a click event, though this is not the same as a real click. For instance, it can't be used to trick a cross-domain iframe document into thinking it was clicked.
All modern browsers support document.elementFromPoint
and HTMLElement.prototype.click()
, since at least IE 6, Firefox 5, any version of Chrome and probably any version of Safari you're likely to care about. It will even follow links and submit forms:
document.elementFromPoint(x, y).click();
- https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint
- https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click
how to trigger a click event by specifying coordinate position(x,y) in react?
It's simulating a click at a position: x,y coordinates with javascript which can be achieved using this
document.elementFromPoint(x, y).click();
Is there a way to trigger a click event on a certain section?
You could check the id of the click-target before triggering the action, like so:
video = document.getElementById('video')
document.body.addEventListener('click', ({ target }) => {
if (target.id === 'video') {
video.style.display = "none";
location.href ="#About";
}
}, true);
Alternatively you could attach the click-handler on the element you care about and thereby avoid triggering the handler too often, like so:
document.getElementById('video').addEventListener('click', ({ currentTarget }) => {
// `currentTarget` refers to the element the handler has been attached to
currentTarget.style.display = "none";
location.href ="#About";
}, true);
Google Maps V3 - Is it possible to trigger the on click event on a specific coordinate (lat, lng) programmatically
You can try passing additional arguments to trigger
method:
var e = {
latLng: new google.maps.LatLng(-35, 151)
};
google.maps.event.trigger(map, 'click', e);
Here is a working example showing infoWindow every time map is clicked (or on programmatic trigger): https://jsfiddle.net/beaver71/5ndjq8ge/
Related Topics
How to Reload or Re-Render the Entire Page Using Angularjs
Merge Two Arrays So That the Values Alternate
How to Calculate 3D Rotation on X and Y Axis from a 4X4 Matrix
Difference and Intersection of Two Arrays Containing Objects
Angular2 Dynamic Input Field Lose Focus When Input Changes
How to Pass Parameters to a Script Tag
How to Perform an Http File Upload Using Express on Cloud Functions for Firebase (Multer, Busboy)
Jqgrid: Change Background Color of Row Based on Row Cell Value by Column Name
What Are the Actual Uses of Es6 Weakmap
How to Check Whether an Object Is a Date
How to Build Query String with JavaScript
How to Rotate a 3D Object on Axis Three.Js
Deep Copy in Es6 Using the Spread Syntax
Safe Evaluation of Arithmetic Expressions in JavaScript
Iterate Over Object Literal Values
Jquery Equivalent of JavaScript's Addeventlistener Method
Getting Error "Form Submission Canceled Because the Form Is Not Connected"