0

I have a script that will reload the page (content) to a random DIV How do I implement this so that the script loads after the div is loaded?

I have the following code ready:

<script>  
$(document).ready(function() {
   $("#getAssignment").click(function() {
      var $divs = $(".assignment");
      if ($divs.length > 0) {
         window.location.hash = "#" + $divs[ Math.floor(Math.random() * 
         $divs.length) ].id;
      }
  });
});    
</script>

5
  • 1
    You can try onload function for that Commented May 21, 2012 at 4:25
  • onLoad event in div should do it Commented May 21, 2012 at 4:27
  • 2
    This question is not very clear. Do you have code that is dynamically loading content into a div? If so, please show that code. Commented May 21, 2012 at 4:30
  • div's don't load. div's are just part of the larger page. If you're changing what's inside a div, then whatever code is doing that can trigger whatever you want to happen afterward... Commented May 21, 2012 at 4:44
  • sorry, this script is usually done when the user click on a button and the script will then select a random div from a list of them (they are classes as "assignment") I want to do the same thing, but instead when this particular page(which is a DIV) is loaded Commented May 21, 2012 at 4:45

1 Answer 1

1
$("div").load(function(){
    blah();
});

This will do what you wanted, but it does not make sense though, since div is not like an image or <script> or a page. (You can't really "load" a <div> anyway.)

Sign up to request clarification or add additional context in comments.

5 Comments

sorry guys, I'm really stupid when it comes to code...how do I make the onload function work with what I have?
sorry, this script is usually done when the user click on a button and the script will then select a random div from a list of them (they are classes as "assignment") I want to do the same thing, but instead when this particular page(which is a DIV) is loaded.
A page is not a DIV. That makes no sense. Pages contain divs.
forgive me for using the wrong terminology. What I am using this for is app created in Dreamweaver using phonegap. So how can I trigger this script when this div is revealed/made active/whatever? @Derek is the "div" part in that the name of the div?
@user1114118 - $("div") means every <div>.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.