Document querySelectorAll() Method - Set the border of all <a> elements in the document that have a "target" attribute: - Javascript DOM

Javascript examples for DOM:Document querySelectorAll

Description

Document querySelectorAll() Method - Set the border of all <a> elements in the document that have a "target" attribute:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
a[target] {//from w w  w . j  a  v  a 2  s  .co  m
    background-color: yellow;
}
</style>
</head>
<body>

<a href="http://www.java2s.com">java2s.com</a>
<a href="http://www.disney.com" target="_blank">disney.com</a>
<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
    var x = document.querySelectorAll("a[target]");
    var i;
    for (i = 0; i < x.length; i++) {
        x[i].style.border = "10px solid red";
    }
}
</script>

</body>
</html>

Related Tutorials