Click here to Skip to main content
11,932,103 members (59,929 online)
Rate this:
Please Sign up or sign in to vote.
See more: Javascript HTML
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 3-Jan-13 0:46am

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 | Mobile
Web02 | 2.8.151126.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2015
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