javascript - HTML Span text toggle -


i have span

<span id="spanactive">show inactive</span> 

trying change text using jquery below:

$('#spanactive').text(($(this).text()=='show inactive') ? 'hide inactive' : 'show inactive'); 

but not working.

use below code

$('#spanactive').text(($('#spanactive').text()=='show inactive') ? 'hide inactive' : 'show inactive'); 

you need use this in event handler having current object in "this".

check working demo @ link

if using this in click event handler span, try below code

$('#spanactive').click(function () {     if($(this).text() == 'show inactive')          $(this).text('hide inactive');     else         $(this).text( 'show inactive'); }); 

check demo @ linkenter link description here


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -