- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › jQuery toggle show/hide on class and change current class?
Hey,
I’m stuck while learning jQuery.
When somebody clicks the anchor ‘.wid1235 a.min’ I want to hide() ‘.wid1235 .content’ and change ‘.wid1235 a.min’ to ‘.wid1235 a.max’
Then when somebody clicks the anchor ‘.wid1235 a.max’ I want to show() ‘.wid1235 .content’ and change ‘.wid1235 a.max’ to ‘.wid1235 a.min’
Because .wid1235 varys, does anybody know a way to do this while not having to define each .wid…. each time?
So far I have this, a whole bunch of unsemantic code :( that doesn’t even work. I was going to use PHP to create new code based on the different widgets :/
$(‘.wid1234 a.min’).click(function(){ $(‘.wid1234 .content’).hide(); $(this).removeClass(‘min’); $(this).addClass(‘max’); });
$(‘.wid1234 a.max’).click(function(){ $(‘.wid1234 .content’).show(); $(this).removeClass(‘max’); $(this).addClass(‘min’); });
$(‘.wid1236 a.min’).click(function(){ $(‘.wid1236 .content’).hide(); $(this).removeClass(‘min’); $(this).addClass(‘max’); });
$(‘.wid1236 a.max’).click(function(){ $(‘.wid1236 .content’).show(); $(this).removeClass(‘max’); $(this).addClass(‘min’); });
$(‘.wid1237 a.min’).click(function(){ $(‘.wid1237 .content’).hide(); $(this).removeClass(‘min’); $(this).addClass(‘max’); });
$(‘.wid1237 a.max’).click(function(){ $(‘.wid1237 .content’).show(); $(this).removeClass(‘max’); $(this).addClass(‘min’); });
});
Thanks a whole bunch!