I have looked and looked and looked but I couldn't find anything on this. So lets say I have this string...
var str = '<script>blah blah blah</script><a>...</a><div>...</div><p>...</p>';
I need to strip out the script tags out of the string along with all the content between the tags. Once the script tag is stripped I need to append it to a textarea. How in the world do I do this with jQuery?
Any help would be much appreciated!
The HTML tags can be removed from a given string by using replaceAll() method of String class. We can remove the HTML tags from a given string by using a regular expression. After removing the HTML tags from a string, it will return a string as normal text.
How to remove script tags from string in php? HTML; $dom = new DOMDocument(); $dom->loadHTML($html); $script = $dom->getElementsByTagName('script'); $remove = []; foreach($script as $item) { $remove[] = $item; } foreach ($remove as $item) { $item->parentNode->removeChild($item); } $html = $dom->saveHTML();
For HTML tags, you can press Alt+Enter and select Remove tag instead of removing an opening tag and then a closing tag.
Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.
since nobody else is going to post a simple and reliably-working routine, i guess i will:
function noscript(strCode){
var html = $(strCode.bold());
html.find('script').remove();
return html.html();
}
alert( noscript("<script>blah blah blah</script><div>blah blah blah</div>") );
//shows: "<div>blah blah blah</div>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With