1

I am making a Chrome extension and I need this button to be clicked so how can I get the click to be recognized?

<button class="btn btn-lg btn-danger btn-bet" onclick="system.play.bet.red();">RED</button>

I tried var test= document.getElementsByClassName("btn btn-lg btn-black btn-bet"); test.click();

but it fails at the beginning.

1 Answer 1

1

Document.getElementsByClassName() returns an array-like object of all child elements which have all of the given class names. Unfortunately, it's not a true JS array. To work with it, you need to "Arrayify" it:

var testElements = document.getElementsByClassName('test');
var testDivs = Array.prototype.filter.call(testElements, function(testElement){
    return testElement.nodeName === 'DIV';
});

In your case, this should work:

var test= document.getElementsByClassName("btn btn-lg btn-black btn-bet")[0];
test.click();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.