I have the following function:
$(document).ready(function () {
$('.contents').hide();
$('.slide').click(function () {
var $this = $(this);
$(this).siblings('.contents').slideToggle(200, function () {
$this.text($(this).is(':visible') ? 'close' : 'open');
});
});
});
and would like to add a further function to the click function. I'm new to jQuery and tried to learn but still does not understand to read it. I thought I can create and append an if-clause but still struggle with that. So I have something like that:
$this.css($('.year').is(':visible') ? 'color', 'red' : 'color', 'green');
if the click function takes place and the .contents is visible change the css setting of .year to red and if not use color green
It would be great if someone can help me out.
Thanks alot.
$this.css('color', $('.year').is(':visible') ? 'red' : 'green');(Move the'color',part before the ?:).is(':visible')will return true if any element with the.yearclass is visible, if you have more than one element with that class it can be an issue.visibility: hiddenoropacity: 0are considered visible. Visible elements need to have a width or height that is greater than zero.