jquery events do not recognise js-added html components? -
I am using js to add form elements to HTML elements. For example, I have an entire & lt; Form & gt; Adding
to a table cell example:
& lt; Form class = "add-comment" & gt; & Lt; Input type = "submit" / & gt; & Lt; / Form & gt;
I try to use JS to invite events based on elements of that newly created form but nothing happens. I should get a warning box What am I doing wrong?
$ ('add-comment') Submit (function () {Alert ('form submit!');});
Thank you I have explained it adequately.
Are you adding the element after registering the submitted event handler? If you do not use a live method to add an event, you must register the event after each new element.
$ ('add-comment') Live ('submit', function () {warning ('form submit!');});
It adds an event to all selected elements, even if they are added in the future.
Comments
Post a Comment