I'm studying a JavaScript book that includes a lot of examples/testing online.
All of this is on one page. A number of excercises revealed one at a time.
As you complete one, it hids it, and shows the next.
The "button" shown for "Check your answer" is not a HTML button.
It's an image with an onclick() method. I want to keep my hands on the keyboard, and I have not found any way via the KB to select and press this "button".
So, KM and a little JavaScript to the rescue. Or so I thought.
Here's the web page in question:
http://asmarterwaytolearn.com/js/16.html
Here's the screen:
Here's the HTML for this "button" and the <div>
that encloses it:
<!--e00-->
<div id="exercise-16-0" class="unhidden">
<p style="margin-top:12px;">This code declares an empty array. Complete it.<br />
<span class="code">var finalScores = ____</span><br />
</p>
<label for="input-16-0">
<input id=
"input-16-0"
type="text" class="codeField" size="57">
<img src="button-check-it.png" class='buttonCheckIt' onmouseover=
"src='button-check-it-hover.png';" onmouseout="src='button-check-it.png';" onclick="checkPattern
(
/\[\];/,'input-16-0',[16,0]
);">
</label>
</p>
</div>
This <div>
block is repeated n times for the number of questions on this page.
So, how can I click on the "button" that is visible?
I have this JavaScript, but it always clicks on the "button" in the first <div>
even when it's not visible.
var aButtons = document.getElementsByClassName('buttonCheckIt');
aButtons[0].click();
I have searched the 'net exhaustively, and can't figure out how to get a ref to the "button" class that is visible.
Can anyone help?
It's a bit*h trying to code complex JavaScript while you're trying to learn it.
TIA.