Reputation: 6519
How do I change the text value from 'close' to 'open' or vice versa when clicking my H4 element?
$(document).ready(function($) {
$('#accordion').find('.accordion-toggle').click(function(){
//Expand or collapse this panel
$(this).next().slideToggle('fast', function(){
var status = $(this).is(':hidden') ? 'close' : 'open';
$(this).next('.accordion-status').html(status);
});
});
});
Upvotes: 1
Views: 88
Reputation: 6031
check below code or go to updated fiddle jsfiddle
$(document).ready(function($) {
var OBJ = '';
$('#accordion').find('.accordion-toggle').click(function(){
OBJ = $(this);
//Expand or collapse this panel
$(this).next().slideToggle('fast', function(){
var status = $(this).is(':hidden') ? 'close' : 'open';
OBJ.find('div.accordion-status').html(status);
});
});
});
Upvotes: 0
Reputation: 49123
According to your current DOM structure, the selector should be:
$(this).prev('h4').find('.accordion-status').html(status);
Because this
refers to the .accordion-content
div, and the accordion-status
div you're looking for is actually before it. Also, it's wrapped with an h4
element.
See Fiddle
Upvotes: 1