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