I need to create a page that displays the number of times a click occurs anywhere on the page along with a list of where the click happened. Also I have a button that clears the list. The button does not clear. The button click is counted as a click on the page body and that is increasing the count and never clearing it.
HTML:
<p><h3>Click count:<span id="output">
</span></h3></p>
<h3>Click locations:</h3>
<div id="clickLocations"></div>
<input id="btn" type="button" value="Validate">
<script>
$(document).ready(function() {
var count = 0;
$("body").click(function (event) {
count += 1; //Count clicks when the body is clicked
if (count > 0) {
$("span#output").html(" " + count);
$("div#clickLocations").append("<ul><li>" + event.pageX + ", " + event.pageY + "</li></ul>"); //Display the x,y location of the click
}
$('#btn').click(function () { //Clear text when the button is clicked
$("div#clickLocations").html('');
$("span#output").empty();
event.stopPropagation();
}); //End button.click
}); //End body.click
}); //End document.ready
</script>