Created
April 3, 2022 05:55
-
-
Save ramajd/b4b1fcd1761aa7ef17b068a0bfda8c54 to your computer and use it in GitHub Desktop.
tag-styler.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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