athammer
athammer

Reputation: 169

Clicking a button on a webpage using JQuery or Javascript

I've been rummaging through the web to how to click buttons for a project I'm working on with Javascript+JQuery(Still not very good). Luckily I was able to find my answer and figured out how to click basic HTML buttons that looked like this(Cut off some of the code just to get the point across).

<div class="ui-block-a">
    <input type="submit" value="Buy Now" data-theme="d">
</div> 

But now I've come across a button like this.

<div id="BuyWithRobux">
    <div data-expected-currency="1" data-asset-type="T-Shirt" class="btn-primary btn-medium PurchaseButton " data-se="item-buyforrobux" data-item-name="Donations" data-item-id="170938328" data-expected-price="2" data-product-id="20832770" data-expected-seller-id="180359" data-bc-requirement="0" data-seller-name="Clone3102">
        Buy with R$
        <span class="btn-text">Buy with R$</span>
    </div>
</div>

Just based off of what I know I don't think I can use what I used to click the last button which was...

 $("input[type='submit']").click();

So my question is how can I click this "button"? I've tried using my old code on it to no avail. I rather not use Selenium, or anything if at all possible. Could anyone help me out with this? If you need anymore information just say what and I'll do my best to provide it, fairly new to this so don't know what to include sadly.

Thank you in advance.

Upvotes: 0

Views: 1388

Answers (1)

T J
T J

Reputation: 43156

By "clicking this button" If you meant to trigger a click on div#BuyWithRobux , You can do so like

$("#BuyWithRobux").click();

or

$("#BuyWithRobux").trigger("click");

The syntax for triggering a click remains the same, all you've to do is to use the right selector to target the element on which you need to trigger the event.

You can learn more about jQuery selectors here

Upvotes: 1

Related Questions