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
Post a Comment