Suppose I have a string of HTML code. I want to use JQuery to remove all <script> tags from the string.
How can I do that?
Note: I want to use JQuery , not REGEX, to do this.
Does this work? $(var).find('script').remove();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This should work for you:
To get the new string with the script tags removed:
JS Fiddle Example – Had to use p instead of script as script broke the fiddle, same principle though.
Actual working answer here (hopefully)
Here is a workaround for the script issue, use replace to swap the script text with something else (try and make it unique) then remove those new tags and use replace again to swap back in case script is used anywhere else in text. Yes, it does use regex, but not to remove the script tags so I’m hoping that’s alright ;):
JS Fiddle Workaround
JS Fiddle Example With Script Text