Here is my HTML:
<section id="artists">
<div class="artists-home" style="display: block;">
<a class="artist-ken" href="#">Ken</a>
<a class="artist-kina" href="#">Kina</a>
</div>
<div class="ken-gallery" style="display: none;">
<a class="gallery-home" href="#"><img src="img/rewind.png" alt="Back to main gallery" width="50"></a>
</div>
<div class="kina-gallery" style="display: none;">
<a class="gallery-home" href="#"><img src="img/rewind.png" alt="Back to main gallery" width="50"></a>
</div>
</section>
This is some jQuery I set up to have the divs fadeIn/FadeOut. Is there a way to combine all of these together or a more elegant way of writing it? I feel I'm repeating things too much.
$('.ken-gallery .gallery-home').click(function( e ){
e.preventDefault();
$('.ken-gallery').fadeOut(function() {
$('.artists-home').fadeIn('slow');
});
});
$('.kina-gallery .gallery-home').click(function( e ){
e.preventDefault();
$('.kina-gallery').fadeOut(function() {
$('.artists-home').fadeIn('slow');
});
});
$('.artist-ken').click(function( e ){
e.preventDefault();
$('.artists-home').fadeOut(function() {
$('.ken-gallery').fadeIn('slow');
});
});
$('.artist-kina').click(function( e ){
e.preventDefault();
$('.artists-home').fadeOut(function() {
$('.kina-gallery').fadeIn('slow');
});
});
<div>
s for.artist-ken
and.artist-kina
? 2) The<div>
s for.ken-gallery
and.kina-gallery
are markeddisplay:none
, so they would be invisible and therefore unclickable, right? \$\endgroup\$.artists-home
div. The two galleries are initially marked asdisplay:none
and shown when.artist-ken
or.artist-kina
are clicked. \$\endgroup\$