Solved

jquery remove script tags

Posted on 2013-06-14
2
1,563 Views
Last Modified: 2013-07-29
Hey,

I have a string and want to rip out all the script tags that are inside and be left with just html.

Thanks
Here is my string
<div class="fn-w-spon"><span class="sponsor-multi-logo"><script type="text/javascript">MultiLogoAd("LOGO",4);</script></span></div>
<h1>Grilling On TV</h1>
    <ul class="tabnav clrfix"><li class="sel">
<span class="lgbtn-lfcap"></span>
<span class="lgbtn-text">overview</span>
<span class="lgbtn-rtcap"></span>
</li>
<li>
<a href="/shows/feeding-the-flames-bobby-flays-barbecue-addiction/pictures/index.html">
<span class="lgbtn-lfcap"></span>
<span class="lgbtn-text">photos<span>(13)</span></span>
<span class="lgbtn-rtcap"></span>
</a>
</li>
<li>
<a href="/grilling-with-fn-chefs/video/index.html">
<span class="lgbtn-lfcap"></span>
<span class="lgbtn-text">videos<span>(13)</span></span>
<span class="lgbtn-rtcap"></span>
</a>
</li>
<li>
<a href="/grilling-on-tv-recipes/package/index.html">
<span class="lgbtn-lfcap"></span>
<span class="lgbtn-text">recipes<span>(78)</span></span>
<span class="lgbtn-rtcap"></span>
</a>
</li>
</ul>



<div class="static-lead-tid-triad clrfix" id="modInst2929280">
<div class="static-lead-tid-triad-primary">
<h3>GRILLING ON FN: BARBECUE WITH BOBBY</h3><a rel="leadi-1" href="http://www.foodnetwork.com/food-network-grilling-central/videos/index.html?channel=64106&amp;video=83165" title="Bobby's Barbecue Addict">
<img src="http://img.foodnetwork.com/FOOD/2011/06/03/FNM_070111-Bobby-Grill-It-010_s4x3_al.jpg" alt="Bobby's Barbecue Addict" height="200" width="266"><span class="video-icon"></span>
</a><p>In his newest show, <em>Bobby Flay's Barbecue Addiction</em>, Bobby steps it up with global flavors, great grilling and true BBQ.</p><a class=" video-link" rel="lead-1" title="Bobby's Barbecue Addict" href="http://www.foodnetwork.com/food-network-grilling-central/videos/index.html?channel=64106&amp;video=83165">Bobby's Barbecue <span class="video-icon">Addiction</span>
</a> <br><a rel="lead-1-s2" title="Behind the Scenes" href="/shows/feeding-the-flames-bobby-flays-barbecue-addiction/pictures/index.html">Go Behind the Scenes</a>
</div><div class="static-lead-tid-triad-secondary">
<div class="static-lead-tid clrfix">
<h4>MEXICAN GRILLING WITH MARCELA</h4><a rel="leadi-2" href="/mexican-made-easy/grilling/index.html" class="thumb" title="Grilling Fiesta Menu"><img src="http://img.foodnetwork.com/FOOD/2012/06/28/VM0504_Full-Food-Spread_s4x3_tz.jpg" alt="Grilling Fiesta Menu" height="90" width="120"></a><p>Get Marcela's grilling menu: Carne Asada Tortas, Grilled Stuffed Jalapenos and more from <em>Mexican Made Easy</em>.</p><a rel="lead-1" title="Grilling Fiesta Menu" href="/mexican-made-easy/grilling/index.html">Grilling Fiesta Menu</a>
</div><div class="static-lead-tid clrfix last">
<h4>THE PIONEER WOMAN'S DOWN-HOME COOKING</h4><a rel="leadi-3" href="/the-pioneer-woman/index.html" class="thumb" title="All About the Pioneer Woman"><img src="http://img.foodnetwork.com/FOOD/2011/11/14/WU-0101_Ree-smiling_s4x3_tz.jpg" alt="All About the Pioneer Woman" height="90" width="120"></a><p>Ree Drummond is a city girl turned rancher's wife turned food blogger and FN host.</p><a rel="lead-2" title="All About the Pioneer Woman" href="/the-pioneer-woman/index.html">About the Pioneer Woman</a>
</div>
</div>
</div>	
<div class="graphic-lead module">
<h2 class="module-hed">A Taste of Bobby's Summer Fare</h2>
<div class="bd clrfix">
<div id="graphic-lead-player-wrap">
<div id="graphic-lead-player"></div>
</div><a href="/food-network-grilling-central/videos/index.html?channel=64106&amp;video=36594" class="thumb thumb-small"><img src="http://images.scrippsnetworks.com/up/images/0129/0129639_92x69.jpg" alt="Bobby's Miami Burger" height="69" width="92"></a>
<a href="/food-network-grilling-central/videos/index.html?channel=64106&amp;video=83165" class="thumb thumb-small"><img src="http://images.scrippsnetworks.com/up/images/0167/0167360_92x69.jpg" alt="Brisket" height="69" width="92"></a>
<a href="/food-network-grilling-central/videos/index.html?channel=64106&amp;video=114546" class="thumb thumb-small"><img src="http://images.scrippsnetworks.com/up/images/0201/0201960_92x69.jpg" alt="Fresh Fruit Sangria" height="69" width="92"></a>
<a href="/food-network-grilling-central/videos/index.html?channel=64106&amp;video=93027" class="thumb thumb-small"><img src="http://images.scrippsnetworks.com/up/images/0169/0169232_92x69.jpg" alt="Tuna Kofte" height="69" width="92"></a>
<a href="/food-network-grilling-central/videos/index.html?channel=64106&amp;video=61284" class="thumb thumb-small"><img src="http://images.scrippsnetworks.com/up/images/0149/0149131_92x69.jpg" alt="Chili Cheeseburgers" height="69" width="92"></a>
<a href="/food-network-grilling-central/videos/index.html?channel=64106&amp;video=78343" class="thumb thumb-small"><img src="http://images.scrippsnetworks.com/up/images/0166/0166600_92x69.jpg" alt="Grilled Potato Salad" height="69" width="92"></a>
<ul class="list list-plain">
<li class="cta"><a href="/food-network-grilling-central/videos/index.html?channel=64106&amp;video=83165">Get addicted to barbecue with Bobby. Watch his latest recipes &gt;&gt;</a></li>
</ul>
</div>
</div>
<script type="text/javascript">SNI.TP.inlinePlayerNoImage( {channelID : '64106', playerType : 'graphic-lead-player'} );</script>
<div id="sponsorCtr1"></div>
<div class="row"><div class="show-plug clrfix alt">
<h3>Ina's Easy Parties</h3>
<a href="/barefoot-contessa/fired-up/index.html">
<img src="http://img.foodnetwork.com/FOOD/2009/06/17/FNM_InaGarten003_s4x3_sm.jpg" alt="Ina">
</a>
<ul class="list">
<li><a href="/barefoot-contessa/fired-up/index.html">Fire Up the Grill</a></li>
<li><a href="/barefoot-contessa/surprise-beach-party/index.html">Surprise Beach Party</a></li>
<li><a href="/barefoot-contessa/perfect-cocktail-party/index.html">Perfect Cocktail Party</a></li>
</ul>
</div><div class="show-plug clrfix">
<h3>Giada's Outdoor Eats</h3>
<a href="/everyday-italian/al-fresco-dining/index.html">
<img src="http://img.foodnetwork.com/FOOD/2012/04/24/GH_Giada-in-red-dress_s4x3_sm.jpg" alt="Giada's Outdoor Eats">
</a>
<ul class="list">
<li><a href="/everyday-italian/al-fresco-dining/index.html">Giada's Al Fresco Dining</a></li>
<li><a href="/giada-at-home/index.html">Giada at Home</a></li>
<li><a href="/giada-at-home/recipes/index.html">Her Top 100 Recipes</a></li>
</ul>
</div></div>


<div class="row"><div class="show-plug clrfix alt">
<h3>Get Grilling With Guy</h3>
<a href="/guys-big-bite/guidos-great-gumbo/index.html">
<img src="http://img.foodnetwork.com/FOOD/2011/03/04/FN_Guy-Fieri-02_s4x3_sm.jpg" alt="Guy Grilling">
</a>
<ul class="list">
<li><a href="/guys-big-bite/guidos-great-gumbo/index.html">Guido's Great Grillin' Grub</a></li>
<li><a href="/guys-big-bite/guys-backyard-bites-green-chile-cheeseburgers/index.html">Backyard Bites</a></li>
<li><a href="/guys-big-bite/recipes/index.html">Guy's Best Recipes</a></li>
</ul>
</div><div class="show-plug clrfix">
<h3>Lighter Grilling With Jamie Deen</h3>
<a href="/home-for-dinner-with-jamie-deen/index.html">
<img src="http://img.foodnetwork.com/FOOD/2012/05/07/FN_Jamie-Deen-Bio_s4x3_sm.jpg" alt="Jamie Deen">
</a>
<ul class="list">
<li><a href="/home-for-dinner-with-jamie-deen/index.html">Get to Know Jamie</a></li>
<li><a href="/home-for-dinner-with-jamie-deen/backyard-bbq/index.html">Backyard BBQ</a></li>
<li><a href="/home-for-dinner-with-jamie-deen/burgers/index.html">Burgers and More Bites</a></li>
</ul>
</div></div>


<div class="row"><div class="show-plug clrfix alt">
<h3>Sandwich King All Summer</h3>
<a href="/sandwich-king/recipes/index.html">
<img src="http://img.foodnetwork.com/FOOD/2011/08/11/Foxtrot_Gallery-01_s4x3_sm.jpg" alt="Jeff Mauro's Top 100 Recipes">
</a>
<ul class="list">
<li><a href="/sandwich-king/recipes/index.html">Jeff Mauro's Top 100 Recipes</a></li>
<li><a href="/sandwich-king/bbq-bonanza/index.html">BBQ Bonanza</a></li>
<li><a href="/recipes-and-cooking/5-sandwich-making-tips/index.html">5 Sandwich-Making Tips</a></li>
</ul>
</div><div class="show-plug clrfix">
<h3>Bobby's Top Grilling Recipes From ...</h3>
<a href="/bobby-flays-barbecue-addiction/recipes/index.html">
<img src="http://img.foodnetwork.com/FOOD/2011/06/27/QF0110H_cuban-skirt-steak-with-tomato-escabeche_s4x3_sm.jpg" alt="Bobby's Top Grilling Recipes">
</a>
<ul class="list">
<li><a href="/bobby-flays-barbecue-addiction/recipes/index.html">Bobby Flay's BBQ Addiction</a></li>
<li><a href="/grill-it-with-bobby-flay/recipes/index.html">Grill It! with Bobby Flay</a></li>
<li><a href="/boy-meets-grill/recipes/index.html">Boy Meets Grill</a></li>
</ul>
</div></div>

Open in new window

0
Comment
Question by:JMRFan4Life
2 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39248884
Hi,
currently offline, so no chance to validate:
http://forum.jquery.com/topic/jquery-removing-script-tags-from-html-string-when-using-html
HTH
Rainer
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 39250381
Let's say that the string above is stored in javascript variable named str.
The following should work:
var re=/<script[^>]*>[\d\D]*?<\/script>/ig;
str=str.replace(re,'');

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now