Jquery / UI / Append or Remove dom elements
Adding or Remove elements to DOM
-
Notes
Adding new element
using 'append()'
Syntax:
eg 1: add some plain text$(referentceElement).append('someValue');
eg 2: add some html elements// using id $('#container').append('hai'); OR //using class $('.container').append('hai'); // using id $('#container').append(' hai
'); OR //using class $('.container').append('hai
');in html
Row Number Remove Row we must have a reference container for appending element. Here id="tbody" is reference container. in jquery
$('#addBtn').on('click', function () { // Adding a row inside the tbody. $('#tbody').append(' '); });text1 text2 1. when we click on 'id="addBtn"' button, elment is appended to container id="tbody"
2. $('#tbody').append() is using for appending the element.Removing elements
using remove()
Syntax:
eg 1: remove using tag name$(referentceElement).remove();
eg 2: remove using reference class$('tr').remove();
eg 3: remove using this$('.removeId').remove(); $(this).remove(); in html
in jquery
$('#removeBtn').on('click', function () { // Adding a row inside the tbody. $('tr').remove(); });