Home > Article > Web Front-end > Code to add and delete elements using JQUERY_jquery
Use JQUERY to add and delete elements
JQuery has methods to add and delete elements.
Mainly divided into internal insertion, external insertion, wrapping, replacement and deletion.
Main method of internal insertion:
append(content) Append content to each matching element.
prepend(content) prepends content inside each matching element.
External insertion:
after(content) Inserts content after each matching element.
before(content) inserts content before each matching element.
Delete:
empty() deletes all child nodes in the matched element set.
remove([expr]) Removes all matching elements from the DOM.
The following example is to click the add button to insert a new row in the last row of the table
and then click the delete button to delete the last row
First grid | < input type='text'/> |