0

can someone help me out to solve a query what's the difference between #1 and #2 note that there is extra [0] in #2 after $(this)

#1 code

$('#a').mouseover(function() {
       $("#a").trigger("click");
    });

#2 code

$('#a').mouseover(function() {
   $("#a")[0].trigger("click");
});
muneebbug
  • 9
  • 3
  • In this context it does not make any difference ... first triggers click on all `a` ids while the second only triggers it for the first element in the `a` id array. This makes more sense with classname or other. – user1452962 Jul 01 '20 at 17:34
  • @user1452962 Yes, it does make a difference. `HTMLElement`s don’t have a `trigger` method in their prototype chain by default, so the second code will almost certainly throw an error. – Sebastian Simon Jul 01 '20 at 17:37
  • only the second code works for me and it triggers a click on hover – muneebbug Jul 02 '20 at 18:10

0 Answers0