Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  133] [ 7]  / answers: 1 / hits: 21541  / 9 Years ago, tue, july 28, 2015, 12:00:00

I need to remove a script tag (<script>...</script>) by its content and/or its src property. Taking as example this:



<script type=text/javascript>
var adfly_id = 2776246;
</script>

<script src=https://cdn.adf.ly/js/display.js></script>


I've tried this code:



jQuery(document).ready(function($){
$('script').each(function() {
if (this.src === 'https://cdn.adf.ly/js/display.js') {
$(this).remove();
}
});
});


But without success (I am using that code from within WP - if anyone is asking why that jQuery syntax), can any give me some advice?



EDIT: The idea here is remove the script to prevent its execution


More From » jquery

 Answers
5

This seems to work:



jQuery(document).ready(function($){
$('script').each(function() {

if (this.src === 'URL_HERE') {

this.parentNode.removeChild( this );
}
});
});

[#65642] Sunday, July 26, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaredsages

Total Points: 273
Total Questions: 97
Total Answers: 105

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
jaredsages questions
;