fadeToggle

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
YoussefSiblini
Forum Contributor
Posts: 206
Joined: Thu Jul 21, 2011 1:51 pm

fadeToggle

Post by YoussefSiblini »

Hi,
I am using the fadeToggle to hide and show a div, it is working fine but I want the text inside another div to be changed depending in the div if it is hidden or visible.

Here is the jsfiddle link to my code:

http://jsfiddle.net/Banzay/kUGRP/


Many thanks,


Jo
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: fadeToggle

Post by social_experiment »

This snippet does what you have in mind; just change it to match your HTML

Code: Select all

$(document).ready(function(){
 $('div#clicker').click(function(){
	$('div#box').fadeToggle("slow", "linear")
	
	if ($('div#clicker').text() == 'Hide' ) {
		$('div#clicker').text("Show");
	}
	else {
		$('div#clicker').text('Hide');
	}
 });
});

// my html
// <div id="clicker">Hide</div>
// <div id="box" class="hideBox" >Hide this content.</div>

“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply