Home > Enterprise >  How can I find the Class Name of this button?
How can I find the Class Name of this button?

Time:08-28

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"  style="margin-bottom:5px; color: #569EA4!important;"> <i  style="font-size: 15px;"></i> Register</a>

I tried it this way but is not working

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

CodePudding user response:

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

CodePudding user response:

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”)

CodePudding user response:

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.

CodePudding user response:

You try to select 2 classes(primary-btn and text-uppercase) in one time.

const myBtn = document.querySelector('.primary-btn');
    myBtn.addEventListener('click', (e)=>{
     console.log('some data')
    })
    ```
  • Related