When getting element by ID, how can I grab the contents within the section?

- 1 answer

Ad

In javascript when I call the "getElementById" method, how can I access the information within that ID section, such as a link for example?

<p id="demo"><a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="someWebsite.com">some link</a></p>

<button onclick="myFunction()"> Grab Link</button>

<script>
    function myFunction() {
        var thisLink = document.getElementById("demo");
        thisLink.(functionToGetSomeLink); //any way to get the link???
}
</script>
Ad

Answer

Ad

you can chain another method onto document.getElementById("demo"); such as:

document.getElementById("demo").value

or

document.getElementById("demo").text

Ad
source: stackoverflow.com
Ad