Guest User

Untitled

a guest
Jan 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <div id="myDiv">Some Content</div>
  2.  
  3. $('#myDiv').click(function(){
  4. //some code
  5. });
  6.  
  7. <div id="myDiv" onClick="divFunction()">Some Content</div>
  8.  
  9. function divFunction(){
  10. //some code
  11. }
  12.  
  13. var myEl = document.getElementById('myelement');
  14.  
  15. myEl.addEventListener('click', function() {
  16. alert('Hello world');
  17. }, false);
  18.  
  19. myEl.addEventListener('click', function() {
  20. alert('Hello world again!!!');
  21. }, false);
  22.  
  23. querySelector('#myDiv').addEventListener('click', function () {
  24. // some code...
  25. });
  26.  
  27. $('span'); // 6,604 ops per sec
  28. document.getElementsByTagName('span'); // 10,331,708 ops/sec
  29.  
  30. $('#jquery a').click(window.testClickListener); // 2,957 ops/sec
  31.  
  32. [].forEach.call( document.querySelectorAll('#native a'), function(el) {
  33. el.addEventListener('click', window.testClickListener, false);
  34. }); // 18,196 ops/sec
  35.  
  36. Go for this as it will give you both standard and performance ....
  37.  
  38. $('#myDiv').click(function(){
  39. //some code
  40. });
  41.  
  42. <div id="myDiv">Some Content</div>
  43.  
  44. $('#myDiv').click(divFunction);
  45.  
  46. function divFunction(){
  47. //some code
  48. }
  49.  
  50. <whatever onclick="doStuff();" onmouseover="in()" onmouseout="out()" />
  51.  
  52. <span id="JQueryClick">Click #JQuery</span> </br>
  53. <span id="JQueryAttrClick">Click #Attr</span> </br>
  54.  
  55. $('#JQueryClick').click(function(){alert('1')})
  56. $('#JQueryClick').click(function(){alert('2')})
  57.  
  58. $('#JQueryAttrClick').attr('onClick'," alert('1')" )//this doesnt work
  59. $('#JQueryAttrClick').attr('onClick'," alert('2')" )
Add Comment
Please, Sign In to add comment