Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-03-2013, 04:16 PM   PM User | #1
garevn
New Coder

 
Join Date: Apr 2011
Posts: 95
Thanks: 13
Thanked 1 Time in 1 Post
garevn is an unknown quantity at this point
expand-collapse text with mouseover/mouseout

This is my current code, but i want a mouseover and mouseout behaviour to a text with no "read more" "read less" "images" ets.
For example

Line one....
Line two....

when mouseover in the table/div with the text, display:

Line one....
Line two....
Line three...
Line four...

when mouseout display back two lines




Code:
<script type="text/javascript">
function showMoreOrLess(thisObj,bonusContent){
     var caption = thisObj.innerHTML;
     //alert(caption);
     if ( caption == "Read more" ) {
         document.getElementById(bonusContent).style.display = "inline";
         thisObj.innerHTML = "Read less";
    
	 } else {
		 
         document.getElementById(bonusContent).style.display = "none";
         thisObj.innerHTML = "Read more";
     }
 }</script>
</head>

<body>
<div id="restOfArticle" style="display:none">blah blah</div>

<a onmouseover="showMoreOrLess(this,'restOfArticle');">Read more</a>

</body>
garevn is offline   Reply With Quote
Old 02-04-2013, 02:30 AM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,761
Thanks: 29
Thanked 452 Times in 446 Posts
jmrker will become famous soon enough
Lightbulb

Just change the order of your code sequence.
Code:
<body>
<div id="restOfArticle" style="display:none">blah blah</div>

<a onmouseover="showMoreOrLess(this,'restOfArticle');">Read more</a>

<script type="text/javascript">
function showMoreOrLess(thisObj,bonusContent){
     var caption = thisObj.innerHTML;
     //alert(caption);
     if ( caption == "Read more" ) {
         document.getElementById(bonusContent).style.display = "inline";
         thisObj.innerHTML = "Read less";
    
	 } else {
		 
         document.getElementById(bonusContent).style.display = "none";
         thisObj.innerHTML = "Read more";
     }
 }</script>
</body>
jmrker is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:52 AM.


Advertisement
Log in to turn off these ads.