Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


XML
<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

1 solution

Here is code it may helpful to you
HTML
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'/>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900