jQuery .toggle() method

0 votes
446 views
added Apr 3, 2018 in jQuery by LC Marshal Captain (25,790 points)
edited Jul 12, 2018 by LC Marshal
<!--Hide/show  or toggle text within certain length-->

<body>
    <span class="teaser">text goes here</span>
      <span class="complete"> this is the complete text being shown</span>
    <span class="more">more...</span>
</body>

<script>
    $(".more").toggle(function(){
        $(this).text("less..").siblings(".complete").show();    
    }, function(){
        $(this).text("more..").siblings(".complete").hide();    
    });
</script>

2 Responses

0 votes
responded Apr 5, 2018 by LC Marshal Captain (25,790 points)
edited Jul 12, 2018 by LC Marshal
<!--Toggle between hide and show for a div.toggleme element-->
<button>Toggle; hide and show for div.toggleme element</button>
<div class="toggleme">This is a paragraph.</div>

<script>
$(document).ready(function(){
    $("button").click(function(){
        $(".toggleme").toggle(1000);
    });
});
</script>

 

0 votes
responded Jun 29, 2018 by LC Marshal Captain (25,790 points)
edited Jul 12, 2018 by LC Marshal
//Slow toggle
$(".btn-mod-card-share").click(function() {
 $( ".social-share" ).toggle( "slow", function() {
 });
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...