user4544229
user4544229

Reputation:

From JQuery to Javascript code

I have this div

<div id="lk_37" class="lk_link" style="display: inline-block">
              <a href="#" class="lk_button_37 lk_post">TADE</a>
</div>

And i want to make one script to check if the button_37 is clicked and if is clicked to go on, if its unclicked then the script should click it.

Also we have a page with different id's of buttons and we want to check them all and click what is unclicked with this particular button.

when the button is clicked the "TADE" is turning on "DTT" this is what i want to check if its clicked or unclicked. we click "TADE" with this class="lk_button_37 lk_post" and its turning on to "DTT" with the same class="lk_button_37 lk_post" as before. so we want to check if "TADE" is on we want the button to be clicked, and if "DTT" is on we want to override it.

The JQuery code for doing this is

$('.lk_button_37:contains(TADE)').click();

And i want to convert this to javascript code for chrome extension.

I've already made up this

var el = document.getElementsByClassName('lk_button_37'); 

for (var i=0;i<el.length; i++) 
{
     el[i].click();
}

But i dont know how to make the code click ONLY the "TADE" button.

Any help would be appreciated. Thanks!

Upvotes: 0

Views: 48

Answers (1)

adeneo
adeneo

Reputation: 318182

Just check the content of the element

var el = document.getElementsByClassName('lk_button_37'); 

for (var i=0;i<el.length; i++) {
    if ( el[i].innerHTML.indexOf('TADE') != -1 ) {
         el[i].click();
    }
}

Upvotes: 4

Related Questions