Reputation: 213
I am working with C# and i am loading a jquery file 1.8.1 in the layout, but there is a module pulling through which is adding another jquery file 1.6.1 is there any way for me to remove it without physically going in and remove it so i need to remove it dynamically.
Thanks.
Upvotes: 0
Views: 95
Reputation: 2791
Try this code snippet for removing script
file dynamically.
$("script[src='jquery-1.6.1.js']").remove()
Upvotes: 1
Reputation: 6992
use follwing function and pass filename you want to remove
function removeScript(filename){
var allsuspects=document.getElementsByTagName('script')
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
if (allsuspects[i] && allsuspects[i].getAttribute('src')!=null && allsuspects[i].getAttribute('src').indexOf(filename)!=-1)
allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
}
}
Upvotes: 1