1

I know we can remove specific script with plugin or php functions. but i am just wondering if it is possible to remove <script> with jquery.

I am trying to remove script <script src="/wp-content/uploads/wp-embed.min.js"></script> with jquery contains wp-embed.min.js but didn't worked. any idea?

jQuery(document).ready(function( $ ){
    $('html').find('script').filter(function(){
    return $(this).attr('src') === 'wp-embed.min.js'
    }).remove();
    console.log("Script removed");
});
1
  • What do you mean by didn't work? Commented Mar 22, 2020 at 6:46

1 Answer 1

1

If you are referring to remove wp-embed.min.js objects (functions, variables and more) from the window object (DOM), then no. It is not possible.

See the following snippet, where I attempt to remove lodash.js by removing its script tag.

console.log("Lodash output #1:", _.sortBy([24,2,556,1,4]));

// remove lodash2
$('script').each(function(i, script){
    var $script = $(script);
    if ($script.attr('src') && $script.attr('src').includes('lodash')) {
         $script.remove();
    }
});

// Lodash test
console.log("Lodash output #2:", _.sortBy([24,2,556,1,4]));
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>

Sign up to request clarification or add additional context in comments.

2 Comments

I am trying remove script from DOM
@Uzair, please elaborate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.