html - I am trying to make a div disappear on click and make another div appear in its place I have wrote and run code using jav

document.getElementById("nextOneButton").onclick = function(){document.getElementById("m

document.getElementById("nextOneButton").onclick = function(){

    document.getElementById("mainFrameOne").style.display="none";
    document.getElementById("mainFrameTwo").visibility="visible";

}

//mainFrameTwo is initially set hidden in terms of visibillity
//nextOneButton is on top of the mainFrameOne in terms of position, when //clicked it should move to next frame. Some what like a slide show
document.getElementById("nextOneButton").onclick = function(){

    document.getElementById("mainFrameOne").style.display="none";
    document.getElementById("mainFrameTwo").visibility="visible";

}

//mainFrameTwo is initially set hidden in terms of visibillity
//nextOneButton is on top of the mainFrameOne in terms of position, when //clicked it should move to next frame. Some what like a slide show
Share Improve this question edited Jun 27, 2015 at 17:59 Walter Chapilliquen - wZVanG 12k8 gold badges44 silver badges64 bronze badges asked Jun 27, 2015 at 17:20 Sharath ZotisSharath Zotis 1652 gold badges2 silver badges7 bronze badges 2
  • What is the error that you are experiencing? However, without knowing your error, I can already tell you that visibility and display are 2 different css properties. – tylerism Commented Jun 27, 2015 at 17:22
  • Please share your sample html – RIYAJ KHAN Commented Jun 27, 2015 at 17:31
Add a ment  | 

3 Answers 3

Reset to default 1

Really you need a button so you can bind your function to the onclick event. Here is a possible solution:

<html>
<head>
<title></title>
<script>
function myFunction() { 
	document.getElementById("mainFrameOne").style.display="none"; 
	document.getElementById("mainFrameTwo").style.display="block"; 
}
</script>
</head>
<body>
<div id="mainFrameOne">
    <p>mainFrameOne</p>
</div>
<div id="mainFrameTwo" style="display:none;">
    <p>mainFrameTwo</p>
</div>
<button onclick="myFunction()">Click me</button>
</body>
</html>

Alternatively, you could use anchor tags to remove the need for the button:

<html>
<head>
<title></title>
<script>
function myFunction() { 
	document.getElementById("mainFrameOne").style.display="none"; 
	document.getElementById("mainFrameTwo").style.display="block"; 
}
</script>
</head>
<body>
<a id="mainFrameOne" onclick="myFunction()" href="#">
    mainFrameOne
</a>
<a id="mainFrameTwo" href="#" style="display:none;">
    mainFrameTwo
</a>
</body>
</html>

        <div id ="activeContent" >


                <div id ="mainFrameOne"> <!-- POSITION MATTERS WHEN YOU WANT TO DO THE DISSAPEARING ACT WITH JAVASCRIPT -->

                    <img src="person.gif" id ="person" width="1350" height ="900">

                    <div id ="backOneButton"> <h4 class ="directionButtonsText">   Back  </h4> </div>

                    <div id ="nextOneButton"> <h4 class ="directionButtonsText">   Next   </h4> </div>

                    <div id = "mainFrameOneTitleBar">

                        <h3 id ="jakesLemonade">Jake's Lemonade Stand</h3>

                    </div> <!-- End of MainFrameTitleBar -->

                    <h3 id = "firstTextJake"> This is Jake, the owner of a small lemonade stand.<br> Like many other small business owners, Jake wants to know <br>what the future holds for him. CloudFin can tell him exactly that. </h3>

                </div> <!-- End of MainFrameOne Div-->


                <div id ="mainFrameTwo"> 

                    <div id ="backTwoButton"> <h4 class ="directionButtonsText">   Back  </h4> </div>

                    <div id ="nextTwoButton"> <h4 class ="directionButtonsText">   Next   </h4> </div>

                    <div id = "mainFrameTwoTitleBar">

                        <h3 id ="lemsLemons">When life gives you lemons, Make lemonade</h3>

                        <script type="text/javascript">


                        </script>

                    </div> <!-- End of MainFrameTitleBar -->

                    <h3 id = "secondTextJake"> How much does each lemon cost?</h3>

                </div> <!-- End of MainFrameTwo -->



        </div> <!-- End of ActiveContent Div -->

If something is not working you can consider using addEventListener. Example:

document.getElementById('button').addEventListener('click', changeVisibility(), null);
function changeVisibility()
{
    document.getElementById('divToHide').style.display = "none";
    document.getElementById('divToShow').style.display = "block";
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744191678a4562463.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信