Question

I am newbie in jsfiddle

I have put a very simple javascript code in jsfiddle http://jsfiddle.net/5bMSp/1/

<script>
function alertme(){
    alert("HI");
}
</script>
<a href="#" onclick="alertme()">click</a>

This simple code works awesome in any browser but not in jsfiddle. Am I missing anything in the jsfiddle?

Was it helpful?

Solution

By default, jsFiddle puts all of your code within an onload handler, like this:

window.onload = function() {
    // ...your code here...
};

That means your alertme function isn't a global, and it has to be for onclick attributes to work.

There's a drop-down on the left, near the top, that controls this behavior. Change it from onLoad to one of the "no wrap" options to make your function global.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top