How to achieve a toggle button (more/less) using jquery html() method -


this current jquery code . changes button value less . not other way around.

$("p").hide();  $(".btn").click(function() {    $("p").toggle();   $(".btn").html("less");   $(".btn").html("more");  }); 

try code

$("p").hide(); $(".btn").html("more"); $(".btn").click(function() {   $("p").toggle();   if($('p').css('display') == 'none') {     $(".btn").html("more");   } else {     $(".btn").html("less");   } }); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -