Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

jQuery .toggle() method

0 votes
13 views
added Apr 3 in jQuery by LC Marshal Lieutenant (13,570 points)
edited Jul 12 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 by LC Marshal Lieutenant (13,570 points)
edited Jul 12 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 by LC Marshal Lieutenant (13,570 points)
edited Jul 12 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.
...