Click here to Skip to main content
11,429,154 members (63,884 online)
Rate this: bad
good
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';
}
</script>
<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
good
Please Sign up or sign in to vote.

Solution 1

Here is code it may helpful to you
var count = 0;
function changeText(){
    count++;
    var id = "p1";
    if(count == 1)
       id = "p2";
    else if(count == 2)
       id = "p3";
    else
       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'/>
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.150428.2 | 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