user3613542
user3613542

Reputation: 5

js how to press button without id?

How to press at this button on js?

<button type="submit" class="btn-lg">Confirm</button>

i tryed this document.getElementsByClassName('btn-lg').Click(); but it not working.

Upvotes: 1

Views: 936

Answers (2)

lshettyl
lshettyl

Reputation: 8181

document.querySelector(".btn-lg").onclick = function() { alert("clicked") }

Upvotes: 1

Dzmtrs
Dzmtrs

Reputation: 446

document.getElementsByClassName returns html collection (array-like object) of the objects which have a specified class. So you should filter unneeded elements by going through the collection (in the same way as you go through an array)

Upvotes: 0

Related Questions