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 -

jquery - ReferenceError: CKEDITOR is not defined -

android - Go back to previous fragment -