.delegate()

In this chapter you will learn:

  1. How to use .delegate() event

.delegate() event

The .delegate() method binds a handler independent of whether the DOM element exists.

<html> <!--   j a v  a 2 s.co m-->
    <head> 
        <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script> 
        <script> 
            $(function(){ 
                $("body").delegate("p","click",function(){ 
                    document.writeln('ouch'); 
                }).css("color", "green"); 
            }); 
        </script> 
    </head> 
    <body> 
        <p>Hit Me! ja va2s.com</p> 
    </body> 
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. Syntax and Description for .die() event
  2. How to unbind all event
Home » jQuery » 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()
.load()
.mousedown()
.mouseenter()
.mouseleave()
.mousemove()
.mouseover()
.mouseout()
.mouseup()
.off()
.on()
.one()
.ready()
.resize()
.scroll()
.select()
.submit()
.toggle()
.trigger()
.triggerHandler()
.unbind()
.undelegate()
.unload()