On 21 Feb, 23:03, Sientz <[EMAIL PROTECTED]> wrote:
> $('a#blackbook').click(function() {
> //HIDE DIVS
> hide_divs();
> //SHOW LISTED DIV
> $('.blackbook').show('fast');
> return false;
> });
you see you got all these functions that basically do the same thing.
if an anchor has an id, they show the corresponding div
I think you could do it like this
$('a[id]').click(function(){
hide_divs();
var x = $(this).attr('id');
$('div[class=" + x + "]').show('fast');
return false;
});
and should do the same thing.
but you could go further, and use classes in a different way.
let's say that instead of calling them divs with 'human' names, we can
use more 'efficient' names, like:
hs_a
hs_b
hs_c
hs_d
...
where hs stands for hide/show (just an example).
in this way the function hide_divs becomes something like
var hide_divs = function(){
$('div[class^="hs"]').hide('fast'); /* this selector looks for
the div(s) that have a classname that starts with the string 'hs' */
};
then you give corresponding id's to the anchors, so the other on I
wrote before:
$('a[id^="hs"]').click(function(){
hide_divs();
var x = $(this).attr('id');
$('div[class=" + x + "]').show('fast');
return false;
});