1

I have this:

<script>
    function myFunction() {
    
    //put the url of the girl into the quotes of imgUrl
    var imgUrl = "https://www.linkpicture.com/q/IMG_4902."
    
    //put the name of the model into the quotes of modelName
    var modelName = "modelName"
    
    //put the link to their instagram into the quotes of instagram
    var instagram = "https://www.instagram.com/gianluca/"
    
    
    document.getElementById("myText").innerHTML = modelName;
    document.getElementById("myImg").src = imgUrl;
    document.getElementById("instagram").innerHTML = instagram;
    }
    </script>
<body onload="myFunction()">
            <img src="" id="myImg" alt="">
            <h2 id="myText"></h2>
            <ul>
                <li><a href="" id="instagram"><i class="fab fa-instagram"></i></a></li>

I am trying to use the variable instagram, and put it into the href, but I cannot figure out how to do it. How is this possible?

3
  • Do you want to put the Instagram variable into href? Commented Jun 16, 2021 at 1:56
  • @YohanMalshika yes, exactly. So I can click the element and it'll take me to instagram. Commented Jun 16, 2021 at 1:56
  • 1
    Did you try this one, document.getElementById("instagram").href = Instagram; ?? Commented Jun 16, 2021 at 1:59

1 Answer 1

2

Add this to the end of your code in the script

document.getElementById("instagram").href = instagram
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.