Toggle Text with jQuery -


i've found a few articles here on topic none seem answer i'm looking for.

here current code:

    $(".email-slide").click(function(){     $("#panel").slidetoggle("slow");     $(this)     .text("close")     .toggleclass("active"); }); 

when select word "email" has class "email-slide" top panel slides down, , word "email" turns white, , word "email" turns word "close".

all far. when clicking "close" though color , panel go normal, word "close" not turn word "email". instead of .text("close") tried .toggletext("class") seems not work. there similar accomplish adding least amount of code possible? thank you!

update - able accomplish using following code, hoping more efficient/shorter way of doing it. if not, let me know. thanks!

$(".email-slide").click(function(){     $("#panel").slidetoggle("slow");     $(this).toggleclass("active"); });  $(".email-slide").toggle(function (){     $(this).text("close") }, function(){     $(this).text("email") }); 

you try:

$(".email-slide").click(function() {     $("#panel").slidetoggle("slow");      $(this).toggleclass("active");      if ($(this).text() == "close")        $(this).text("email")     else        $(this).text("close");  }); 

or instead of comparing text() value, can test $(this).hasclass("active").

h.t.h. :)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -