How to remove some elements within the Div using JQuery

Sathish Nadarajan
SharePoint MVP
Published On :   17 Aug 2015
Visit Count
Today :  4    Total :   10574

In the previous article, we saw how to export the data into Excel using Javascript. At that time, I faced some issues like, while exporting, the HTML contains some unwanted Image Tags, Anchor Tags etc., So before writing them on the Excel, I need to remove all those elements.

This can be done in two ways. Either we can manipulate the HTML string and using some regex, we can remove the unwanted elements. Or else, we can go with JQuery to get the corresponding Elements and using the remove() method.

The syntax is very straight forward.

 $(‘#MyDiv img’).map(function(){

The above syntax will remove all the images within the Div “MyDiv”. In the same manner, we can remove all the unwanted Elements.

Though it looks very small, this will definitely save at least an hour of effort.

Happy Coding,

Sathish Nadarajan.