Delegate (), live (), and jquerydelegate in jquery

Source: Internet
Author: User

Delegate (), live (), and jquerydelegate in jquery

The delegate () method adds one or more event handlers to the specified element (a child element of the selected element ).
For example, add an event to the span tag in the div whose id is showspan.

<Div id = "showspan"> <span> showspan ** showspan </span> </div> <span> outspan </span> <script language = "JavaScript"> <! -- // The effect is to click a section <div id = "showspan">. The span tag adds a span tag to the end of the span tag, you can also click to add a new span tag for the newly added span tag. The added tag does not need to listen to its click Event $ ("# showspan "). delegate ("span", "click", function () {$ (this ). after ("<span> showspan ** showspan </span>") ;}); // --> </SCRIPT>

The live () method attaches one or more event handlers to the selected element (you cannot add events to its child elements)
For example, add an event to the p tag.

<P class = "showp"> pppppppp </p> <script language = "JavaScript"> <! -- $ (". Showp "). live ("click", function () {$ (this ). after ("<p> pppppppp </p>") ;}); // --> </SCRIPT>

The above is all the content of this article. I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.