Hello,
This is my first week with javascript and I think that I'm already convinced that jquery is the way to go.
I'm trying to write jquery code that will show answers to questions when a radio button is clicked, and make the answers disappear if it's not. Someone was kind enough to show me a javascript solution, but I with jquery, a more elegant solution is possible. I've attempted the code, but I fear that nothing actually happens! Any help would be appreciated:
Code:
$(document).ready(function(){
$(':radio').click(function(){
if ($(this).attr('checked')) {
$('.answer').show();
} else{
$('.answer').hide();}
})
}
)
My html:
Code:
<form action="" method="post" name="Question1"> <label>
<input type="radio" name="ex1" value="wrong1" id="ex1"/>
<span class="answer1" lang="latex">x^{3}</span><span class="answer">THis should print if this button is selected</span></label>
<br />
<label>
<input type="radio" name="ex1" value="wrong2" id="ex2" />
<span class="answer2" lang="latex">2x+1</span><span class="answer">This should print if this button is selected</span></label>
<br />