Document querySelector() Method - Get the first <a> element in the document that has a "target" attribute: - Javascript DOM

Javascript examples for DOM:Document querySelector

Description

Document querySelector() Method - Get the first <a> element in the document that has a "target" attribute:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
a[target] {//  ww  w.  ja  v a 2  s . com
    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() {
    document.querySelector("a[target]").style.border = "10px solid red";
}
</script>

</body>
</html>

Related Tutorials