[jQuery] triggering events with selected <option>
What I want to do should be very simple... but somehow just doesn't
work:
I want to control the hiding/showing of paragraphs with a <select>
element.
Without further adue, the code:
$("select.numberPages").change(function(){
if ( $("option.a").selected ) {
$("#p1").show();
$("#p2, #p3, #p4, #p5").hide();
}
if ( $("option.b").selected) {
$("#p1, #p2").show();
$("#p3, #p4, #p5").hide();
}
if ( $("option.c").selected) {
$("#p1, #p2, #p3").show();
$("#p4, #p5").hide();
}
if ( $("option.d").selected) {
$("#p1, #p2, #p3, #p4").show();
$("#p5").hide();
}
if ( $("option.e").selected) {
$("#p1, #p2, #p3, #p4, #p5").show();
}
})
And for the HTML:
A. Number of pages :
<select name="numberPages" class="numberPages">
<option class="a">1</option>
<option class="b">2</option>
<option class="c">3</option>
<option class="d">4</option>
<option class="e">5</option>
</select>
<p id="p1">content
<p id="p2">content
<p id="p3">content
<p id="p4">content
<p id="p5">content
I hope someone has the time and kindness to figure this out...