jquery use html () after setting the content, how to make the new elements event and original elements bind the same event?

HTML:

<div id="1">
<div>
<ul>
<li><button id="button">a</button></li>
<li><span>1</span></li>
</ul>
</div>
</div>
<div id="2">
<ul>
<li></li>
</ul>
</div>

JQUERY:

$("#button").live("click",function(){
var s = Number($(this).parents("ul").find("span").text());
$(this).parents("ul").find("span").text(s+1);
$("#2 li").html($("#1 li").html());
});

The problem is that when I click on the button , span's number add number 1 and DIV#2 set up a new button , how can i add DIV#1 span number when i click DIV#2 new , I means how this function can find the right parents and span?

here is DEMO

i want to add number 1 when i click new button ,that's all,thanks!

Answers


You can check changed Demo.

$("#button").live("click",function(){        
    var span = $('#1 span');
    span.html(Number(span.html())+1);    
    $("#2 li").html($("#1 li").html());
});

Need Your Help

Singleton with subclassing in java

java design-patterns singleton

The most common way of implementing a singleton in java is to use a private constructor with a public accessor method of the form --

Notification about object method invocation

iphone objective-c ios ipad

Is there a way in objective-c to find out if a method of an object has been invoked, by lets say something similar to KVO?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.