Reputation: 125
Let's say that I got code like that:
<div class="div">
<input type="submit" value="Button" class="button1">
</div>
And then when I put in the console this code:
document.getElemetsByClassName('button1')[0].click();
It does click the button, but when I try the same thing in jQuery with arrays:
array = document.getElementsByClassName('div');
$(array[0]).find('button1').click();
It does not work and does not return any error messages so I don't know what is wrong. Thanks from above for help.
Upvotes: 2
Views: 132
Reputation: 167240
The selector you are using is a tag selector. Change it to class selector:
$(array[0]).find('.button1').click();
//----------------^ Add a . here.
I would also better change this to:
$(".div .button1").trigger("click");
Works better this way, using trigger()
.
Upvotes: 0
Reputation: 20750
button1
is class
. You should add a dot(.) before button1
to select button1
class
like following.
$(array[0]).find('.button1').click();
Upvotes: 2