How to simulate click of a button and not both?

0

I think the question seems confusing, but calm, I will explain better. Type, on a given page, there are 2 buttons with the same class, having as difference only its value, and an attribute "origin". Example:

<input type='button' class='botao' onclick='envia(this,0);' origin='Roll < 49' value='Roll < 49'/>

<input type='button' class='botao' onclick='envia(this,1);' origin='Roll > 51' value='Roll > 51'/>

I tried to simulate clicks using jquery, but I was not successful since I clicked both buttons at the same time and not just one. My code:

var button1 = $('.clDicePlay').attr('value','Roll > 51'),
            button2 = $('.clDicePlay').attr('value','Roll < 49');

button1.trigger('click');

Someone can help me. Thank you in advance!

    
asked by anonymous 10.07.2016 / 17:08

2 answers

0

To get an element by its value in jQuery, use the value=[] selector. Example:

<input type='button' class='botao' origin='Roll < 49' value='Roll < 49'/>

<input type='button' class='botao' origin='Roll > 51' value='Roll > 51'/>
var button1 = $(':input[value="Roll < 49"]'),
    button2 = $(':input[value="Roll > 51"]');

button1.click(function(){
    envia(this, 0);
});

button2.click(function(){
    envia(this, 1);
});

button1.trigger('click');
    
10.07.2016 / 17:39
1

Set a specific ID for each.

<input type='button' id='foo' class='bo..

With this, just apply the click trigger

$('#foo').trigger('click');
    
10.07.2016 / 17:14