I have written jquery but there is repetition of code lines. I wish to minimize these lines of code. I haven't an idea how to do it? Can any one help me would be appreciated.
HTML
<div class="content-wrapper">
<div class="publish-content">
<div class="content-title">
<h5>Publised content</h5>
<span><img src="images/accordion-arrow.png" alt="down arrow"/></span>
</div>
<div class="content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><hr>
</div>
</div>
<div class="upcoming-content">
<div class="content-title">
<h5>Upcoming content</h5>
<span><img src="images/accordion-arrow.png" alt=" down arrow"/></span>
</div>
<div class="content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p><hr>
</div>
</div>
</div><!--content section ends---------->
Please note: I have removed here html of future content.
jquery
$('.publish-content').click(function() {
var clicks = $(this).data('clicks');
if (clicks) {
// odd clicks
$(this).children('.content').slideUp();
$(this).children('div:first').children('span').css({'transform' : 'rotate(0deg)'});
} else {
// even clicks
$(this).children('.content').slideDown();
$(this).children('div:first').children('span').css({'transform' : 'rotate(90deg)'});
$('.upcoming-content').children('.content').slideUp();
$('.upcoming-content').children('div:first').children('span').css({'transform' : 'rotate(0deg)'});
$('.future-content').children('.content').slideUp();
$('.future-content').children('div:first').children('span').css({'transform' : 'rotate(0deg)'});
}
$(this).data("clicks", !clicks);
});
$('.upcoming-content').click(function() {
var clicks = $(this).data('clicks');
if (clicks) {
// odd clicks
$(this).children('.content').slideUp();
$(this).children('div:first').children('span').css({'transform' : 'rotate(0deg)'});
} else {
// even clicks
$(this).children('.content').slideDown();
$(this).children('div:first').children('span').css({'transform' : 'rotate(90deg)'});
$('.publish-content').children('.content').slideUp();
$('.publish-content').children('div:first').children('span').css({'transform' : 'rotate(0deg)'});
$('.future-content').children('.content').slideUp();
$('.future-content').children('div:first').children('span').css({'transform' : 'rotate(0deg)'});
}
$(this).data("clicks", !clicks);
});
Please note: I have removed here jquery of future content. That's it.