Suppose I had 3 divs, each div has at least one hide/show button. The problem is when I click a show button, both 3 divs will show ups.
Example:
<div id="container">
<div class="course">
<a href="#" class="clickshow"> Click me to Show</a>
<div class="hidden">
Hello
</div>
</div>
<div class="course">
<a href="#" class="clickshow"> Click me to Show</a>
<div class="hidden">
Hello
</div>
</div>
<div class="course">
<a href="#" class="clickshow"> Click me to Show</a>
<div class="hidden">
Hello
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(".course a.clickshow").click(function(){
$(".course div.hidden").show();
})
});
</script>
When I click show button, it shows up all.
Then, I tried to change every div into differrent course id. It end up...
<div id="container">
<div class="course-1">
<a href="#" class="clickshow"> Click me to Show</a>
<div class="hidden">
Hello
</div>
</div>
<div class="course-2">
<a href="#" class="clickshow"> Click me to Show</a>
<div class="hidden">
Hello
</div>
</div>
<div class="course-3">
<a href="#" class="clickshow"> Click me to Show</a>
<div class="hidden">
Hello
</div>
</div>
</div>
<script>
$(document).ready(function(){
$(".course-1 a.clickshow").click(function(){
$(".course-1 div.hidden").show();
})
$(".course-2 a.clickshow").click(function(){
$(".course-2 div.hidden").show();
})
$(".course-3 a.clickshow").click(function(){
$(".course-3 div.hidden").show();
})
});
</script>
This will works very well, each show button will show it's own div.
However,if I have 100 courses in a page, my codes will be longer than ever.
How can I make it works with SHORTEST code ?
Thanks You.