Is there a way in JavaScript to find out the exact position of a click within an element, like its distance from the left, right, or center? I'm struggling to determine whether the clicked area is on the left, center, or right side.
https://i.stack.imgur.com/8bpwe.png
Below is the table I am working with -
<tr id="ing-117">
<td style="width: 15%; vertical-align: middle; display: none;"><img src="arrow-left.png" class="arrow left hidden"></td>
<td style="width: 70%; text-align: left;" class="txt center lefted"><div class="in"></div>2 cups ice</td>
<td style="width: 15%; vertical-align: middle;"><img src="arrow-right.png" class="arrow right hidden"></td>
</tr>
Here's my current JavaScript code snippet -
$('.arrow').unbind('click')
.bind('click', function(event, is_triggered){
var th = $(this);
var x = event.clientX;
var y = event.clientY;
console.log(x , y);
When I click on the second <td>
, it prints undefined undefined
in the console.
Your help will be greatly appreciated. Thank you.