I’ve been making a concerted effort to improve my javascript skills lately by reading as much javascript code as I can. In doing this I’ve sometimes seen the javascript: prefix appended to the front of event handler attributes in HTML element tags. What’s the purpose of this prefix? Basically, is there any appreciable difference between:
onchange='javascript: myFunction(this)'
and
onchange='myFunction(this)'
?
Probably nothing in your example. My understanding is that
javascript:is for anchor tags (in place of an actualhref). You’d use it so that your script can execute when the user clicks the link, but without initiating a navigation back to the page (which a blankhrefcoupled with anonclickwill do).For example:
Rather than: