I have a bunch of pages on a website that may or may not contain links pointing to xyz.com.

When a page is loading, I have to determine if the hyperlink on the page contains a link to xyz.com (it can be something.xyz.com or anything.xyz.com).

Once found, I have to append a string ?BX.ref\_id=AMX-DO-1938 to the end of it.

So a hyperlink like `https://something.xyz.com/blog/category/` will become `https://something.xyz.com/blog/category/?BX.ref_id=AMX-DO-1938`

How can I do it? This is what I have come up so far.

```
var matchingElements = $("a[href*='/xyz.com/']")

var hrefs = matchingElements.map(function(index, element) {
    return $(element).attr('href');
});

$.each(matchingElements, function(index, val) { 
    $(this).attr('href', function(){ 
        return this.href + '?BX.ref_id=AMX-DO-1938';
    });
}

```