Jquery could not select elem by id -


<input type="button" id="elem" value="search">  <script>   var elem1 = $("#elem");   elem1.onclick = hello;    function hello() {     alert("hello");   } </script> 

i don't understand why couldn't select id element jquery, how js document.getelementbyid

as elem1 jquery object, doesn't have onclick property. can use either of these method bind event handler.

here, [0] underlying dom element can use onclick

elem1[0].onclick = hello; 

or use .on() bind event handler

elem1.on('click', hello); 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -