How to check src script match then reassign src

I need to check each src tag value script, and if there is a match, I would like to change the script attribute of the src attributes ... Something like this:

var scripts = document.getElementsByTagName("script")[0].src

for (i=0;i<scripts.length;i++){
  if(scripts[i] == "something.js"){
    document.getElementsByTagName("script")[i].src = "this.js"
  }
  else {}
}} 
+3
source share
1 answer
var scripts = document.getElementsByTagName("script");

for (i=0;i<scripts.length;i++){
  if(scripts[i].src == "something.js"){
    scripts[i].src = "this.js";
  }
}
+8
source

Source: https://habr.com/ru/post/1773096/


All Articles