Connecting Tech Pros Worldwide Help | Site Map

How to show/hide class with CSS/javascript?

Newbie
 
Join Date: May 2007
Location: Texas
Posts: 9
#1: 2 Weeks Ago
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?

Expand|Select|Wrap|Line Numbers
  1. <div id="story" class="text_exposed_root">Yay for being around yada
  2.  
  3. <span class="text_exposed_hide">...</span>
  4.  
  5. <span class="text_exposed_show"> yada on Sunday!</span>
  6.  
  7. <span class="text_exposed_hide">
  8. <span class="text_exposed_link">
  9. <a onclick="CSS.addClass($("story"), "text_exposed");">read more</a>
  10. </span>
  11. </span>
  12. </div>
Thanks for any help.
RamananKalirajan's Avatar
Needs Regular Fix
 
Join Date: Mar 2008
Location: Chennai - India
Posts: 348
#2: 1 Week Ago

re: How to show/hide class with CSS/javascript?


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

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE> New Document </TITLE>
  5. <META NAME="Generator" CONTENT="EditPlus">
  6. <META NAME="Author" CONTENT="">
  7. <META NAME="Keywords" CONTENT="">
  8. <META NAME="Description" CONTENT="">
  9. <script type="text/javascript">
  10. function readMore(){
  11.     document.getElementById('readMore').style.display="none";
  12.     document.getElementById('shorten').style.display="block";
  13.     document.getElementById('more').style.display="block";
  14. }
  15.  
  16. function shorten(){
  17.     document.getElementById('readMore').style.display="block";
  18.     document.getElementById('shorten').style.display="none";
  19.     document.getElementById('more').style.display="none";
  20. }
  21. </script>
  22. </HEAD>
  23.  
  24. <BODY>
  25. <div style="float:left;width:400px;">
  26. <span style="float:left;">
  27. 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.
  28. Why do we use it?
  29. </span>
  30. <span id="more" style="float:left;display:none;">
  31. 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).
  32. </span>
  33. <span style="float:left;cursor:pointer;color:#0034f5;" id="readMore" onclick="readMore()">
  34. Read More...
  35. </span>
  36. <span style="float:left;cursor:pointer;display:none;color:#0034f5;" id="shorten" onclick="shorten()">
  37. Shorten Content...
  38. </span>
  39. </div>
  40. </BODY>
  41. </HTML>
Thanks and Regards
Ramanan Kalirajan
Reply