I want to style differently links that are have the anchor same as the href attribute value:
<a href="https://google.com">https://google.com</a>
Is it possible to do this with CSS alone, or do I need JavaScript for this?
I want to style differently links that are have the anchor same as the href attribute value:
<a href="https://google.com">https://google.com</a>
Is it possible to do this with CSS alone, or do I need JavaScript for this?
Thanks for your comments on this being impossible in CSS.
I ended up with this JavaScript solution:
document.addEventListener("DOMContentLoaded", () => {
for (item of document.querySelectorAll("a[href*='//']")) {
if (item.getAttribute('href') == item.innerHTML) {
//item is an HTML link with anchor same as innerHTML.
//in this case, I just add a class to it
item.classList.add('no-after-content')
}
}
})
A simple solution with javascript . Hope this helps.
<a href="https://google.com">https://google.com/</a><br />
<a href="https://google.com">https://yahoo.com/</a>
<script>
var myCol = document.getElementsByTagName("a");
for(i=0; i< myCol.length; i++){
if((myCol[i].href).trim() == (myCol[i].innerHTML).trim()){
myCol[i].style.color = "red";
}
}
</script>