html - How to trigger click event using JavaScript on querySelectorAll -
this question has answer here:
in jquery have following code
$("li#credit").trigger('click');
this code triggers click event on li has id credit.
now using javascript
document.queryselectorall("li#credit").click();
i getting error:
click() not function
the page working have multiple elements id "credit", need trigger click event on <li>
has id credit.
queryselectorall
returns nodelist object (source) , not dom element. nodelist object contains dom elements.
your code needs change first element , call click()
:
document.queryselectorall("li#credit")[0].click();
if want trigger .click()
event elements can for
loop
for(var = 0; i<elems.length; i++) { elems[i].click(); }
Comments
Post a Comment