Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the Document</title> </head> <body> <a id="a" href="#welcome">link</a> <script> // attribute alert(a.getAttribute('href')); // #welcome // property alert(a.href ); // full URL in the form http://site.com/page#welcome </script><!-- mark the div to show "siteName" here --> <div show-info="siteName"></div> <!-- and "bookName" here --> <div show-info="bookName"></div> <script> // code finds the marked item and shows what is requested let site = { siteName: "W3Docs", bookName: "Javascript" }; for(let div of document.querySelectorAll('[show-info]')) { // insert the corresponding info into the field let field = div.getAttribute('show-info'); div.innerHTML = site[field]; // first W3Docs into "siteName", then Javascript into "bookName" } </script> </body> </html>