April 1, 2019

Add Link Check - JQuery

There's a cool jQuery trick to check to see if all the hyperlinks on the current page are going to a certain URL. This is useful if you want a quick way to make sure that links are pointing to a Dev environment.

Enable jQuery

if the site isn't using jquery, you'll need to add it, if you don't know it doesn't hurt to run this as it won't break the site (Unless the site is using some bleeding edge jQuery code.)

Open up the Chrome Console and paste the following:

var script = document.createElement("script");
script.setAttribute("src", "[https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js](https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js)");
script.addEventListener('load', function() {
var script = document.createElement("script");
document.body.appendChild(script);
}, false);
document.body.appendChild(script);

You should get back the following:

<script src="[https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js](https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js)"></script>

Now run this:

$("a[href*='[company.com](http://company.com/)']").css("color", "orange");

This will highlight any link going to [company.com](http://company.com) to orange. You probably won't see any changes on your site, so change it to something reasonable.

If something did get changed, you should see how many links got changed:

init(213)

Comments

Add your Comments

Feel free to leave a comment about this post.

- Feel Free to add HTML to your comment!