I know this question is redundant, yet I really require expert advice:
I am using jQuery the wrong way in the following scenario and would appreciate as many suggestions as possible to produce the most efficient code:
I have a webpage with with a parent div with ID = "#bottomrightbox". This parent "#bottomrightbox" div contains a series of divs with IDs such as "#20111", "#20112", "#20113"....
Currently I have assigned a link (i.e with id #link20111) for each of these divs (i.e. div with id #20111) that when clicked hides the children of #bottomrightbox div and shows the specific div. So my code as seen below simple responds to the onclick function of each link and then hides all the divs within the parent div and shows the specific div that is assigned to it by name. My problem is I have more than 40 divs with specific links that follow this type of naming sequence and so I have repetitive lines of jQuery code that should be reduced to a single function that takes cares of this process. I would appreciate if anyone could show me a simple way to write a jQuery function that allows for me to show each div when the link that is assigned to it is clicked.
My code works the following way:
link with id #link20111 -> click -> hide children of #bottomrightbox -> show div with id #20111
link with id #link20112 -> click -> hide children of #bottomrightbox -> show div with id #20112
link with id #link20113 -> click -> hide children of #bottomrightbox -> show div with id #20113
<script type="text/javascript">
$(document).ready(function () {
$('#link20111').click(function () {
$('#bottomrightbox').children().hide();
$('#20111').fadeIn(500);
});
$('#link20112').click(function () {
$('#bottomrightbox').children().hide();
$('#20112').fadeIn(500);
});
$('#link20113').click(function () {
$('#bottomrightbox').children().hide();
$('#20113').fadeIn(500);
});
});
</script>
All help is deeply appreciated.
Here is the sample/jsfiddle for this code: http://jsfiddle.net/uhnxj/