JQuery append function for buttons -


i want use jquery append function append button after button.plz help

var button = $("<button>hi there</button>"); button.click(function() {     alert("hi back!"); }); button.appendto("#tablecell"); 

the above code used append button after text in table.but want append button after button

var button = $("<button>hi there</button>"); $("#tablecell").on('click', button, function() {     alert("hi back!"); }); button.insertafter("#tablecell"); 

or

 $('#tablecell').insertafter(button); 

why need .on() delegate

because button, append dom after page load means after dom ready. ordinary binding not work there , need delegate (aka, live) event handler.

$(target).on(eventname, handlerfunction) // ordinary binding 

but

$(container).on(eventname, target, handler) // delegate binding 

you've option .delegate() looks:

$(container).delegate(target, eventname, handlerfunction); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -