chhameed
chhameed

Reputation: 4456

jquery: fire a function when a specific div loads?

I want to fire a function when a specific div is load.
by searching I found that onload is not functioning on div .

so I tried it by an image that work perfect But problem is that it fire the function only one time . for example when I refresh the page it fire the function but if I again refresh the page it can't fire the function again.. why is it happened ?

Any suggestion please

EDIT

<div id="divID">
  <img src="myimage.jpg" alt="image"/>
</div>

$('#divID').load(function() {
   // code to function
 });

Upvotes: 2

Views: 2986

Answers (2)

Vijaya Raaja Velu
Vijaya Raaja Velu

Reputation: 43

If #divID is loading in delay . You can use timeout function as below

setTimeout( function () { //Do something }, 5000); });

5000 is delay of 5 secs

Upvotes: 0

Marwan
Marwan

Reputation: 2402

You can call the function inside a script tag after the div closing tag Example

<div>
//something inside
</div>

<script type="text/javascript">
//call the function here 
functionName();
</script>

Upvotes: 4

Related Questions