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

jQuery .toggle() method

0 votes
8 views
added Apr 3 in jQuery by LC Marshal Second Warrant Officer (6,010 points)
edited Apr 6 by LC Marshal

Hide/show  or toggle text within certain length

HTML

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

 

JS

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

1 Example

0 votes
responded Apr 5 by LC Marshal Second Warrant Officer (6,010 points)
edited Apr 6 by LC Marshal

Toggle between hide and show for a div.toggleme element

<script>
$(document).ready(function(){
    $("button").click(function(){
        $(".toggleme").toggle(1000);
    });
});
</script>
<button>Toggle; hide and show for div.toggleme element</button>
<div class="toggleme">This is a paragraph.</div>
lazacode.org - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.
...