Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
92
rated 0 times [  95] [ 3]  / answers: 1 / hits: 17625  / 12 Years ago, thu, june 21, 2012, 12:00:00

This is my second question about clicking buttons in JavaScript but this one I'm really stuk on: I'm trying to click an image button with javascript however there's not much to go on as the source only gives this information about the image button



<div id=claimBtnDv style=bottom:-30px; position:absolute; right:0; margin-top:0;>
<input type=image class=btnClaim src=websitebuttonimage onclick=alert('buttonclicked');>
</div>


I tried to do document.getElementById('claimBtnDv').click() but no success , are there other methods to use?


More From » image

 Answers
15

If you can't change the HTML and you need to click the image using javascript, you can go into the child nodes to find the image. This is pretty easy since a class name is provided.



var nodes = document.getElementById('claimBtnDv').childNodes;

for ( i = 0; i < nodes.length; i++ ) {
if ( nodes[i].className === btnClaim ) {
console.log(clicking!);
nodes[i].click();
break;
}
}

[#84738] Wednesday, June 20, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
luna

Total Points: 698
Total Questions: 114
Total Answers: 93

Location: Israel
Member since Wed, Apr 14, 2021
3 Years ago
luna questions
;