Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Show / Hide Text Blocks Question

Posted on 2013-01-21
Medium Priority
Last Modified: 2013-01-22
Hi everyone,

I have some text on the page arranged liked this:

Block 1 of text

Block 2 of text

Would someone be able to help me so that if you click on the title it shows the block of text underneath and if you click on the title again it hides the text?


Question by:TLN_CANADA
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 19

Expert Comment

by:Rikin Shah
ID: 38804206
LVL 39

Accepted Solution

Pratima Pharande earned 2000 total points
ID: 38804233
try this

<title>my javascript show script</title>

<script type="text/javascript">
      function showStuff(id) {
      if (document.getElementById(id).style.display == 'block')
            document.getElementById(id).style.display = 'none';
            document.getElementById(id).style.display = 'block'


<p><a href="#" onclick="showStuff('answer1'); return false;">What price are your apples?</a><br>
<span id="answer1" style="display: none;">Our apples are 30 pence each. If you buy 10 or more we can sell them at a discounted bulk rate of 25 pence each.</span></p>


Author Comment

ID: 38804275
Thank you pratima, it works except when I put php in the output it does not hide on the page load:

<p><a href="#" onclick="showStuff('answer1'); return false;">Today:</a><br>
<span id="answer1" style="display: none;"><?php foreach ($res as $k => $v) {
    echo str_replace('__', $v, $html[$k]) . PHP_EOL;
} ?>

Open in new window

Do I need to put something around the php for it to work?


What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 39

Expert Comment

by:Pratima Pharande
ID: 38804320
try puttin simple PHP text only rather than Loop

Author Comment

ID: 38804327
Tell you tell me how to print the results of the loop into another variable and then print this variable here as I need the results of the loop in this block. Thanks for your help :)

Author Comment

ID: 38808682
Thanks, I have this figured out now.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question