javascript - testing a function in jsfiddle -


sorry, stupid question here. if post question javascript or jquery, people - create jsfiddle.

so, did. question getting divs slide using jquery but, can't basic javascript function run in jsfiddle.

http://jsfiddle.net/ubq6e/

<div onclick="showit()">hello</div> function showit() { alert('hi'); } 

a div, click on call javascript function, jsfiddle says function not defined. can not in jsfiddle?

you've selected default onload option in jsfiddle.

this causes site wrap entire code within callback function, meaning showit function not global function required dom0 inline event handlers.

there several work arounds, in personal order of preference:

  1. don't use dom0 inline handlers, they're really old school - element.addeventlistener() instead , separate markup js.

  2. use window.showit = function() { ... } instead force function appear in global name space.

  3. select 1 of "no wrap" options


Comments