I'm using jQuery to get a click on an 'a' element. I have a list of those links where each one has a class which by him I'm capturing the click.
I would like to know which of the links has been clicked (I have an attribute 'setid' for each link) and also get the point where the mouse has been clicked.
How could this be accomplished?
example of the code:
<a href="#" class="newItem" setid="28">click me</a> $('.newItem').click(function (e) { alert(e.attr('setid')); });
EDIT: OK, so to get the position I would use e.pageX
The buttonPressed() callback function will have a returned event object which has all the data about the HTML element that is clicked on. To get the clicked element, use target property on the event object. Use the id property on the event. target object to get an ID of the clicked element.
Try this. $(document). ready(function() { $(this). click(function(event) { alert(event.
To pass this element to JavaScript onclick function and add a class to that clicked element, we can set the onclick attribute to a function that's called with this . to set the onclick attribute to the a elements to call onClick with this .
To use jQuery methods you have to wrap this with a call to jQuery.
$('.newItem').click(function () { alert($(this).attr('setid')); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With