I have the following code that should change the value of h2 from "Show more" to "Show less", and then back when the parent element is clicked.
The if () test checks OK and changes the text to "Show less", but it will not change it anymore and always displays a "Show more" warning, so it just does not detect the else () condition.
I searched high and low to find out why, but haven't found a solution yet.
I know this is a question with noob, so apologize for this, but I tried to find a solution before posting here.
Thank.
$('#panels > .feature').click(function() {
if($(this).children('h2').val('Show More')) {
$(this).children('h2').text('Show Less');
alert('Show More was found');
}
else {
$(this).children('h2').text('Show More');
alert('Show Less was found');
}
$(this).next(".info_box").animate(
{'height':'toggle'}, 'slow', 'linear'
);
});
This HTML address:
<div id="panels">
<div id="Email" class="feature">
<h1>LiveContent</h1><h2>Show More</h2>
</div>
<div class="info_box">Information will go in this div which should slide in and out.</div>
<div id="Email" class="feature">
<h1>Publishing Solutions</h1><h2>Show More</h2>
</div>
<div class="info_box">Information will go in this div which should slide in and out.</div>
<div id="Email" class="feature">
<h1>Title 1</h1><h2>Show More</h2>
</div>
<div class="info_box">Information will go in this div which should slide in and out.</div>
</div>
source
share