0

I am trying to set a click on this button with the code below using class name or id name but I am unable to find it.

<a href="mobile/register.php" class="primary-btn text-uppercase" style="margin-bottom:5px; color: #569EA4!important;"> <i class="fa fa-user-plus fa-2x" style="font-size: 15px;"></i> Register</a>

I tried it this way but is not working

document.getElementsByClassName(“primary-btn text-uppercase”).click();

4 Answers4

1

If you wanna reach both class at the same time: document.querySelector('text-uppercase.primary-btn')

You can't put a space between classes when you use getElementsByClassName.

document.getElementsByClassName(“text-uppercase”) or document.getElementsByClassName(“primary-btn”)

theBlob
  • 19
  • 5
1

you can do it with a query selector like this,

document.querySelector(".primary-btn.text-uppercase").addEventListener('click' , function(){
    console.log("clicked") ; 
} )

but you should always do this with ids.

Ankit
  • 1,359
  • 1
  • 2
  • 15
0

document.querySelector(".primary-btn.text-uppercase").click();

Yash Narola
  • 101
  • 4
0

You try to select 2 classes(primary-btn and text-uppercase) at the same time

const myBtn = document.querySelector(".primary-btn");
myBtn.addEventListener("click", (e) => {
  console.log("some data");
});
Abito Prakash
  • 4,368
  • 2
  • 13
  • 26