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>
4
  • 1
    You want to hide div1 every time that div2 changes? Apr 8, 2013 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 Apr 8, 2013 at 19:12
  • Have a look at this thread; it should help you: stackoverflow.com/questions/4979738/…
    – cjp666
    Apr 8, 2013 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 8, 2013 at 19:47

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.