How to show/hide class with CSS/javascript?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • quushich
    New Member
    • May 2007
    • 9

    How to show/hide class with CSS/javascript?

    I want to be able to stop a paragraph mid-sentence and provide a 'more' link that then disappears when clicked and the rest of the paragraph appears in place. Much like many blogs and social sites do.

    Below is code from just such a site... so what is needed to make it work?

    Code:
    <div id="story" class="text_exposed_root">Yay for being around yada
    
    <span class="text_exposed_hide">...</span>
    
    <span class="text_exposed_show"> yada on Sunday!</span>
    
    <span class="text_exposed_hide">
    <span class="text_exposed_link">
    <a onclick="CSS.addClass($("story"), "text_exposed");">read more</a>
    </span>
    </span>
    </div>
    Thanks for any help.
    Last edited by acoder; Nov 9 '09, 08:46 AM. Reason: Added [code] tags
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    I have given an example, please have a look over that. Please post back if you have any doubts or queries on the same...

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
    <script type="text/javascript">
    function readMore(){
    	document.getElementById('readMore').style.display="none";
    	document.getElementById('shorten').style.display="block";
    	document.getElementById('more').style.display="block";
    }
    
    function shorten(){
    	document.getElementById('readMore').style.display="block";
    	document.getElementById('shorten').style.display="none";
    	document.getElementById('more').style.display="none";
    }
    </script>
    </HEAD>
    
    <BODY>
    <div style="float:left;width:400px;">
    <span style="float:left;">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    Why do we use it?
    </span>
    <span id="more" style="float:left;display:none;">
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
    </span>
    <span style="float:left;cursor:pointer;color:#0034f5;" id="readMore" onclick="readMore()">
    Read More...
    </span>
    <span style="float:left;cursor:pointer;display:none;color:#0034f5;" id="shorten" onclick="shorten()">
    Shorten Content...
    </span>
    </div>
    </BODY>
    </HTML>
    Thanks and Regards
    Ramanan Kalirajan

    Comment

    Working...