On jquery delegate of and live of
- 2020-06-19 09:40:29
- OfStack
The delegate() method adds one or more event handlers to the specified element, which is a child of the selected element
For example, add an event to the span tag in div, where id is showspan
<div id="showspan"><span>showspan**showspan</span></div>
<span>outspan</span>
<SCRIPT LANGUAGE="JavaScript">
<!--
// And the effect is to click 1 A paragraph <div id="showspan"> In the span Labels will be in span After the label 1 a span Tags, for new ones span The TAB can also be added by clicking on it 1 a span Tags. New tags do not need to be monitored click The event
$("#showspan").delegate("span", "click", function(){
$(this).after("<span>showspan**showspan</span>");
});
//-->
</SCRIPT>
The live() method appends one or more event handlers to the selected element (events cannot be added to its children)
For example, add events to the p tag
<p class="showp">pppppppp</p>
<SCRIPT LANGUAGE="JavaScript">
<!--
$(".showp").live("click", function(){
$(this).after("<p>pppppppp</p>");
});
//-->
</SCRIPT>
This is the end of this article, I hope you enjoy it.