Jitender
Jitender

Reputation: 7969

Load method in jquery

I want to alert massage when div having id b is loaded.

<div id='a'>a</div>
<div id='b'>b</div>
<div id='c'>c</div>


$(function(){
$('#b').load(function(){
alert(0)
})
})

Upvotes: 0

Views: 31

Answers (2)

Claudio Redi
Claudio Redi

Reputation: 68440

Load event doesn't apply to div elements. As far as I'm aware the best you can do is

<div id='a'>a</div>
<div id='b'>b</div>

<script>
   alert(0);
</script>

<div id='c'>c</div>

Upvotes: 1

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

You cannot apply the event load or ready to a div elements. You could use this code, that alert when all DOM is ready or loaded:

$(document).ready(function() {
  alert("0");
});

or

$(window).load(function() {
   alert("0");
});

Upvotes: 0

Related Questions