In this post, I show how you can add and remove new element within your web page with jQuery.
There are two approaches for doing this –
- Pre-made all elements
- Dynamically create new element
The first case is easy but you have to create all of the element at once and hide them which is not required currently.
When you have to add an element you need to display the element one by one and for removing hide them.
Here the problem is – there are multiple unused elements are available which occupies space within your code and makes it messy even if you don’t have needed some of the elements.
The second solution is better than the first here you create and remove an element dynamically when you have to require.
In the demonstration, I am using the second solution.