I'm a newbie in jquery/javascript and i need some help! I'm trying to click only one button from the true condition response, but all the time the script will click on all the buttons of the true condition response.. I don't know how to solve this.
$(".enemy-box").each(function(index) {
var pret = Number($(this).find('.attack-price').text().replace(/,/g, '').split('$')[1]);
var name = $(this).find('.enemy-name').text().replace(/\s+/g, " ");
var x = $(this).find(document.getElementsByClassName("btn attack-btn")); // this will click on all the true conditions buttons
/* I have tried with this but stil not working. the script will click on all the true conditions buttons!
var len = $(this).find(document.getElementsByClassName("btn attack-btn")).length;
var random = Math.floor( Math.random() * len ) + 0;
var x = $(this).find(document.getElementsByClassName("btn attack-btn")).eq(random);
*/
if (name.indexOf("Test") == -1 && pret <= 39.99 ) {
x.click();
}
});
Any help is much appreciated, thank you in advance!
Aucun commentaire:
Enregistrer un commentaire