Click here to Skip to main content
13,147,050 members (62,135 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hi this code is to manage Two paragraphs if i have three paragraphs then how can i manage

i have three paragraphs defaultly we are displaying First Paragraph
if i press button once it displaying second Paragraph
if i press button second it should be display Third Paragraph

i don't know how to display this

<script type="text/javascript">
function changeText(){
    document.getElementById('boldStuff').innerHTML = 'Fred Flinstone';
<p>Welcome to the site <b id='boldStuff'>dude</b> </p>
<input type='button' onclick='changeText()' value='Change Text'/>
Posted 2-Jan-13 23:46pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Here is code it may helpful to you
var count = 0;
function changeText(){
    var id = "p1";
    if(count == 1)
       id = "p2";
    else if(count == 2)
       id = "p3";
       count = 0;
    document.getElementById(id).style.display = "";
<p id="p1">Welcome to the site</p>
<p id="p2" style="display:none;">Welcome to the site2</p>
<p id="p3" style="display:none;">Welcome to the site3</p>
<input type='button' onclick='changeText()' value='Change Text'/>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100