Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryGenerators and Converters

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Hide and Reveal Content, On Demand — Read More-Less Example

A "[Read More]" link is clicked to reveal new content.

A "[Read More]" link is clicked to reveal new content. Previously existing content is pushed down to make room. When new content appears, the "[Read More]" link is changed to "[Read Less]" which, when clicked, removes the content. The "[Read More]" and "[Read Less]" links exchange background and text colors.

Here is the example:

Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever. [Read More]

Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever. Ipsum lorum whatever.

 
Here is the source code:

The paragraph tag (the inserted content) —

<p 
   id="readmoreblock" 
   style="display: none; 
      border-color: purple; 
      background-color: yellow; 
      border-style: dashed; 
      border-width: 3px; 
      color: purple; 
      font-weight: bold; 
      padding: 20px; 
      margin: 20px;">
Ipsum lorum whatever. Ipsum lorum whatever. 
Ipsum lorum whatever. Ipsum lorum whatever. 
Ipsum lorum whatever. Ipsum lorum whatever. 
Ipsum lorum whatever.
</p>

 
The links —

<span 
   id="readmoremore" 
   onclick="DoReadMore('readmoremore','readmoreless','readmoreblock');" 
   style="line-height: 16px; 
      font-size: 14px; 
      font-weight: bold; 
      font-family: sans-serif; 
      color: purple; 
      background-color: yellow;">
<nobr>[Read More]</nobr></span>
<span 
   id="readmoreless" 
   onclick="AbandonReadMore('readmoreless','readmoreblock','readmoremore');" 
   style="display: none; 
      line-height: 16px; 
      font-size: 14px; 
      font-weight: bold; 
      font-family: sans-serif; 
      background-color: purple; 
      color: yellow;">
<nobr>[Read Less]</nobr></span>

 
The JavaScript —

<script type="text/javascript" language="JavaScript"><!--
function DoReadMore(tid1,tid2,tid3) {
document.getElementById(tid1).style.display = "none";
document.getElementById(tid2).style.display = "";
document.getElementById(tid3).style.display = "";
}
function AbandonReadMore(tid1,tid2,tid3) {
document.getElementById(tid1).style.display = "none";
document.getElementById(tid2).style.display = "none";
document.getElementById(tid3).style.display = "";
}
//--></script>

Back to:
Hide and Display Content On Demand
Hide and Reveal Content, On Demand: How It Works

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC