I used
Method 1:
$("button").click();
Result: Cannot read property 'click' of null
Method 2:
$("button").trigger("click");
Result: Cannot read property 'trigger' of null
I used
Method 1:
$("button").click();
Result: Cannot read property 'click' of null
Method 2:
$("button").trigger("click");
Result: Cannot read property 'trigger' of null
-
2
Does the button have
id
value? Does the web page containjquery
file? – Ankit Agarwal Commented May 16, 2018 at 6:19 - 1 Possible duplicate of stackoverflow./questions/37667139/… . If you mean it, of course. Your question is not plete. – vahdet Commented May 16, 2018 at 6:21
-
1
In chrome console, you can use
$0
to refer the selected element – Thum Choon Tat Commented May 16, 2018 at 6:22 -
1
Try
$("button")[0].click();
– Pankit Kapadia Commented May 16, 2018 at 6:32 - 1 var intervalID; $('.button').click(function(){ intervalID = setInterval(function(){ $("._njrw0").click(); },3000); }); when i run this code in chrome console i got "cannot read property click of null" – JustCode Commented May 16, 2018 at 10:51
2 Answers
Reset to default 2solution if an ID and jQuery not available:
document.getElementsByTagName("button")[0].click();
If your page doesn't reference jQuery, you can simply find the element by its ID using javascript and attach click event to it as follows:
document.getElementById('mainbar').addEventListener("click", function()
{
console.log('main bar clicked');
});
Using jQuery:
$('#buttonid').click();