How do I move this JavaScript event from an inline event to its own .JS file? -
happened across snip of js i've managed make work uses, i'm brand new javascript, i'm unsure whether i've understood how & why works. stands, it's inline (inside html tag, i'd see either in own .js file can used several thousand links on 1 of several hundred pages on site i'm putting together.
the purpose of javascript looking kill or disable link (and link) on page after had been clicked once. didn't want disappear, i'd seen mention of, made un-clickable.
anyway, found. assistance appreciated.
<a href="testvid.avi" onclick="this.onclick=function(){return false;}"><div id="box1">this video file</div></a>
again, question is, how take onclick event & place in own .js file. thank you.
with plain js can use same code:
document.getelementbyid('videolink').onclick = function() { this.onclick = function() { return false; } }
with jquery can try:
$("#videolink").one('click', function() { $(this).click(function() { return false; }); });
upd:
<a href="testvid.avi" id="videolink"><div id="box1">this video file</div></a> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script type="text/javascript" src="filename.js"></script>
filename.js
$(function() { $("#videolink").one('click', function() { $(this).click(function() { return false; }); }); });
Comments
Post a Comment