0

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>
jeff_jr
  • 17
  • 1
  • 1
    You want to hide div1 every time that div2 changes? – nicosantangelo Apr 08 '13 at 19:12
  • 1
    What triggers the content to show in div2? This code will only run when the page is loaded. You would want to run this code after any JS that's adding to DIV2 – Adam Plocher Apr 08 '13 at 19:12
  • Have a look at this thread; it should help you: http://stackoverflow.com/questions/4979738/fire-jquery-event-on-div-change – cjp666 Apr 08 '13 at 19:15
  • We're going to be loading variable data into div2 resulting in a multitude of HTML files. There is no trigger, only page load. – jeff_jr Apr 08 '13 at 19:47

1 Answers1

0

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.

Travis J
  • 81,153
  • 41
  • 202
  • 273