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
Post a Comment