04-21-2009, 10:47 PM
|
#2 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
Quote:
Originally Posted by allworknoplay
can someone explain to me fundamentally what this does?
<a href="javascript:myFunction();">
I assume that the first part "javascript" is calling
my javascript up in the header?
|
This executes a javascript event when the link is clicked on
Quote:
Originally Posted by allworknoplay
<script type="text/javascript"></script>
And myFunction is calling a function that is within that script?
|
Yes
Quote:
Originally Posted by allworknoplay
So hypothetically, if I did this, then it's the same philosophy?
<script type="text/whatever"></script>
<a href="whatever:myFunction();">
|
No because the "javascript" protocol (which isn't actually a protocol) has a special meaning to the browsers.
Quote:
Originally Posted by allworknoplay
Also, why is it that when calling a function outside of the
javascript tags, you use the parenthesis "()"..
But within it, you don't? Like this...
Code:
<script type="text/javascript">
var clickCount = 0;
function documentClick(){
document.getElementById('clicked').value = ++clickCount;
}
document.onclick = documentClick;
</script>
How come:
document.onclick = documentClick;
Doesn't use parenthesis? Shouldn't it be?
document.onclick = documentClick();
|
Thats because you assign a callback to the event, if you call it directly it will be the result of the "documentClick()" function, which returns null (void).
__________________
|
|
|