GoekhanDev
GoekhanDev

Reputation: 518

Javascript DOM | Find element by inner Text and replace every element that matches

Here's the code I scraped from the internet and done something to it, I don't know anything about Javascript so don't blame me if this code is a total mess :)

My Code:

var aTags = document.getElementsByTagName("a");
var searchText = "VRX";
var found;

for (var i = 0; i < aTags.length; i++) {
  if (aTags[i].textContent == searchText) {
    found = aTags[i];
    break;
  }
}

Array.from(found).forEach(
    function(element, index, array) {
       document.getElementsByClassName("nova").style = "text-shadow:0.5px 0.5px 5px gold;color:gold;background: url(https://static.nulled.to/public/assets/sparkling.gif);-webkit-animation: randclanim 2s infinite linear;";
    }
);

HTML:

enter image description here

Upvotes: 0

Views: 304

Answers (1)

H.T
H.T

Reputation: 130

As I see screenShot of your code, you should parsing span elements for example I write below code:

// if you want just A elements use below line 
var els = document.getElementsByTagName("span");


	
  for (i = 0; i < els.length; i++) {
  	console.log(els[i].textContent +"--" + i );
     els[i].className.lastIndexOf('nova')!=-1 && els[i].textContent.lastIndexOf('VRX')!=-1  ?  els[i].style = "text-shadow:0.5px 0.5px 5px gold;color:gold;background: url(https://static.nulled.to/public/assets/sparkling.gif);-webkit-animation: randclanim 2s infinite linear;" : 0;
   
  }
<body>
<div>
  <span class="nova">HI</span>
   <br>
   <br>
  <a > VRX </a>
</div>
<div>
<a> <span class="nova">VRX</span></a>
</div>
 
</body>

I hope it useful ;)

Upvotes: 1

Related Questions