How to remove some elements within the Div using JQuery


Sathish Nadarajan
SharePoint MVP
Published On :   17 Aug 2015
Visit Count
Today :  2    Total :   9354
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

SharePoint Office 365 Tool
Simple & Powerful Tool for Migration, Security & Reporting. Free Trial


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(){
 $(this).remove();
 });
 

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.

SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

KWizCom Scan