I have a list of buttons. Need to select the only one button(third) from the list. So, once I click on a 'new button', it has to execute actions from button #3(ThirdButton). My problem is that <li>
tags don`t have the id, so my iteration below is unsuccessful.
<div class="listButtons" id="anyId">
<ul class="test">
<li>
<input value="Btn1" class="btn" name="Elem 1" title="Elem 1" type="button">
</li>
<li>
<input value="Btn2" class="btn" name="Elem 2" title="Elem 2" type"button">
<input value="Btn3" class="btn" name="Elem 3" title="Elem 3" type"button">
<input value="Btn4" class="btn" name="Elem 4" title="Elem 4" type"button">
</li>
</ul>
<div>
I have tried: 1.
const newButton = $("#someId");
const buttonsList = $("ul.test")
const thirdButton = buttonsList.find("input[name='Elem 3']")
newButton.click(() => {
thirdButton.click()
})
2.
const newButton = $("#someId");
const buttonsList = $("ul.test")
const thirdButton = buttonsList.find("input[name='Elem 3']")
$(function() {
$("ul.test").find(".btn").each((index, elem) => {
let elementValue = $(elem).attr("value")
if(elementValue === "Btn3") {
newButton.click(() => {
$(elem).click()
})
}
})