Why can't I trigger or simulate user click using chrome's console in browser? like I have a link on a page I do $('#app .mylink').click()
it should go somewhere.
$
in Chrome's console is an alias for document.querySelector()
, except when it's not. If $
is declared in the page, usually by jQuery, $
in the console will point to that instead.
Calling click
on a jQuery object representing an a
element won't perform the native navigation, but calling click
on the native HTMLElement
will. If you know the page you're working with uses jQuery, you'll need to retrieve the native HTMLElement
from the jQuery object:
$('#app .mylink')[0].click(); // assuming you want to click the first element returned
But if jQuery's not involved, that won't work. Best to be unambiguous:
document.querySelector('#app .mylink').click();
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