So I had a problem where I needed a page to refresh but I couldn't use the .click() method on it because it does not work on href. I couldnt use window.location because I was trying to render a subtab which can be directly accessed due to security reasons. Then I stumbled upon this post:
https://stackoverflow.com/a/12801548/1864552
His solution works but I was hoping someone could give a good explanation on why this works.
jQuery click function triggers the event handlers that were bound with jQuery and simulates an event to try to trigger other click related handlers, but can't exactly reproduce the browser's native behavior :
Although .trigger() simulates an event activation, complete with a synthesized event object, it does not perfectly replicate a naturally-occurring event.
If you add [0], you don't call jQuery's function but the standard DOM function, which perfectly works in this case.
Because using $('#element')[0] gets the DOM element, therefore you can use javascript functions for that element
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With