'Search and replace data-reactid

I am trying to look for data-reactid value and replace it with another value.

Here is the code:

Book a Room.

trying to use the code to replace ".0.2.2" with ".0.2.3"

(function () {
    var link = document.querySelectorAll('a[data-reactid*=".0.2.2"]') //change example.com to any domain you want to target
    var searchString = ".0.2.2" //the string to be searched forEach
    var replacementString = ".0.2.3" //the replacement for the searched string 
    
    links.forEach(function(link){
        var original = link.getAttribute("data-reactid");
        var replace = original.replace(searchString,replacementString)
        link.setAttribute("data-reactid",replace)
    })
})();


Solution 1:[1]

Just change this

var link = document.querySelectorAll('a[data-reactid*=".0.2.2"]')

to this

var links = document.querySelectorAll('a[data-reactid*=".0.2.2"]')

But keep in mind that you should not change the attributes set by React itself

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 EzioMercer