Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's exactly what you asked for.</p> <p>Fiddle: <a href="http://jsfiddle.net/ZZEk8/118/" rel="nofollow">http://jsfiddle.net/ZZEk8/118/</a></p> <p>Add to HTML:</p> <pre><code>&lt;span class="log"&gt;&lt;/span&gt; </code></pre> <p>JS:</p> <pre><code>var clicks = [], updatedClicks = ""; $('.clickable').on('click', function (ev) { //We don't use .bind() after jQuery 1.7, use .on() now. var $div = $(ev.target); var $display = $div.find('.display'); var offset = $div.offset(); var x = ev.clientX - offset.left; var y = ev.clientY - offset.top; $display.text('x: ' + x + ', y: ' + y); clicks.push(x + "/" + y); updatedClicks += "coordinates" + " " + clicks.length + ":" + " " + clicks[clicks.length -1] + "&lt;br /&gt;"; $('.log').html(updatedClicks); }); </code></pre> <p><strong>UPDATE:</strong> OP requested a way to limit the coords and delete one. </p> <p>Fiddle: <a href="http://jsfiddle.net/ZZEk8/125/" rel="nofollow">http://jsfiddle.net/ZZEk8/125/</a></p> <pre><code>var clicks = [], updatedClicks = [], limit = 5; $('.clickable').on('click', function (ev) { var $div = $(ev.target); var $display = $div.find('.display'); var offset = $div.offset(); var x = ev.clientX - offset.left; var y = ev.clientY - offset.top; $display.text('x: ' + x + ', y: ' + y); //Stops adding at limit if (clicks.length &lt; limit){ addCoord(x,y); } }); $('.delete').on('change', function(ev) { if(clicks.length){ var selection = this.value -1; deleteCoord(selection); } else { //If there are no coords to delete run this return false; } }); function addCoord (x,y){ clicks.push(x + "/" + y); updatedClicks.push("Coordinates" + ":" + " " + clicks[clicks.length -1] + "&lt;br /&gt;"); $('.log').html(updatedClicks.join(" ")); } function deleteCoord(selection) { clicks.splice(selection, 1); updatedClicks.splice(selection, 1); $('.log').html(updatedClicks.join(" ")); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload