javascript - Get element by ID is not working -


verry simple question:

i have html:

<div id="test" style="border: 1px solid red; width: 300px;">     text </div> 

and js in seperate .js file:

$('#test').hover(function(){     alert('it's working'); }); 

i no errors fire bug , googled lot on this. please help: why code not working?

thanks in advance

you need wait until dom loaded, otherwise, javascript run before #test exists. can wrapping code in ready function, this:

$(document).ready( function() {     $('#test').hover(function(){         alert("it's working");     }); }; 

this tricky problem can go unnoticed, because won't error jquery operating on empty selection.

alternatively, move script bottom of page, executes after rest of dom loads, preference approach way.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -