Skip to content

Instantly share code, notes, and snippets.

@ramajd
Created April 3, 2022 05:55
Show Gist options
  • Save ramajd/b4b1fcd1761aa7ef17b068a0bfda8c54 to your computer and use it in GitHub Desktop.
Save ramajd/b4b1fcd1761aa7ef17b068a0bfda8c54 to your computer and use it in GitHub Desktop.
tag-styler.html
<html>
<body>
<div>
<a href="example.com/123123213/123123">first example</a>
<a href="another link">2nd example</a>
<a href="this-is-the-2nd-example.com">third example</a>
<a href="example/asdasd/bbb">another example</a>
</div>
</body>
<style>
.my-class {
padding: 0.7rem;
border-radius: 45px;
background-color: purple;
color: white;
}
</style>
<script>
tags = document.getElementsByTagName('a')
for (const tag of tags) {
href = tag.getAttribute('href');
if (href.indexOf("example") >= 0) {
tag.setAttribute('class', 'my-class')
}
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment