1

When I open a website on the browser. Now I want to click button through javascript console which every browser has. The button have class and the website is not using jquery so the code will be pure javascript.

document.getElementsByClassName('btn-orange').trigger('click'); document.getElementsByClassName('btn-orange').click();

Thank you for taking time for helping me.

Deepesh singh
  • 101
  • 11
  • 1
    Possible duplicate of [What do querySelectorAll, getElementsByClassName and other getElementsBy\* methods return?](https://stackoverflow.com/questions/10693845/what-do-queryselectorall-getelementsbyclassname-and-other-getelementsby-method) – Sebastian Simon Nov 07 '17 at 17:51
  • 1
    `document.getElementsByClassName('btn-orange')` returns an array of elements. – Prakash Sharma Nov 07 '17 at 17:52
  • What are you asking? This question is really difficult to understand. Can you try to make it easier to read? Thanks. – Chris Sharp Nov 07 '17 at 17:52

1 Answers1

2
document.getElementsByClassName('btn-orange')[0].click();

This will work, because document.getElementsByClassName('btn-orange') will give u an array of selected DOM elements, even if u have only one element with this classname, it will be on position first of the array, and then u call call click event on that element.

misss-popcorn
  • 591
  • 2
  • 12