简体   繁体   中英

Javascript: Hiding/Showing divs

As a newbie to Javascript, I'm a little stuck here. All I'm trying to do is this: when any content appears in div2, div1 is to disappear.

<html>
<head>
<title>Untitled Document</title>

<script src="jquery-1.9.1.min.js"></script>
<script type=”text/javascript”>
$(document).ready(function(){
   if ($("#div2").html().length > 0) {
     $('#div1').hide();
   }                                           
 });
</script>
</head>

<body>
    <div id="div1">Bonus Bet</div>
    <div id="div2">Random Text</div>

</body>
</html>

There are no built in handlers for this. What you need to do is hook into your function which would change the content in div2, and then hide div1. If there is hardcoded data inside of div2 then your approach will work just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM