Jump to content

onClick first click only?


sciencebear

Recommended Posts

use a variable that stores if something has been clicked.

example:

<script type="text/javascript">
window.onload =  function() {
// use var to check if a link has been clicked
var clickedOnce = false;
document.getElementById('my_link').onclick = function() {
	// will only alert when clickedOnce is false
	if(!clickedOnce) {
		clickedOnce = true;
		alert('you clicked me');
	}
}
}
</script>
<a href=# id="my_link">clickme</a>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.