.load()
Syntax and Description
.load(handler)
handler
is a function to execute when the event is triggered.
Return value is the jQuery object, for chaining purposes.
.load(handler)
binds an event handler to
the load JavaScript event.
This method is a shortcut for .bind('load', handler)
.
The load event is sent to an element when it and all its sub-elements have been completely loaded.
For example, consider a page with a simple image as follows:
<img src="book.png" alt="Book" id="myImage" />
The event handler can be bound to the image.
$('#myImage').load(function() {
$.print('loaded.');
});
As soon as the image has been loaded, the loaded
will be printed.
Loaded event
The following code adds load event to input tag. And if
the element is higher than 100 pixel it will print big
or it will
print small
.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--from w w w. j av a 2s . com-->
$('input').load(function(){
if($(this).height() > 100) {
$(this).addClass('big');
}else{
$(this).addClass('small');
}
});
});
</script>
</head>
<body>
<body>
<input type="text" />
</body>
</html>
The code above generates the following result.
Javascript Tutorial Event
Event
Event attributes
event.keycode
event.clientX/clientY
pageX/pageY
Cancel event
Event target
bind
.blur()
.change()
.click()
.error()
.dblclick()
.delegate()
.die()
.focus()
.hover()
.keydown()
.keypress()
.keyup()
.live()
.mouseenter()
.mouseleave()
.mousemove()
.mouseover()
.mouseout()
.mouseup()
.off()
.on()
.one()
.ready()
.resize()
.scroll()
.select()
.submit()
.toggle()
.trigger()
.triggerHandler()
.unbind()
.undelegate()
.unload()
Event
Event attributes
event.keycode
event.clientX/clientY
pageX/pageY
Cancel event
Event target
bind
.blur()
.change()
.click()
.error()
.dblclick()
.delegate()
.die()
.focus()
.hover()
.keydown()
.keypress()
.keyup()
.live()
.load()
.mousedown().mouseenter()
.mouseleave()
.mousemove()
.mouseover()
.mouseout()
.mouseup()
.off()
.on()
.one()
.ready()
.resize()
.scroll()
.select()
.submit()
.toggle()
.trigger()
.triggerHandler()
.unbind()
.undelegate()
.unload()