-1

Soo i'm working on this project for class and I made an internal link. But instead of the link taking my to the section I want it to take me to, it opens another tab. Like I did the id= but it still didn't work.

Here is the code

<!DOCTYPE html5>
<html>
<head>
<title>States</title>
<style>
body{
    background-image:url("https://codehs.com/uploads/8558c426dc8bb1b2385c7e52f947e35b");
    background-attachment:fixed;
    background-size:cover;
    border:9px dashed #a50202;
    padding:10px;
 }
h2{
    color:#811806;
    text-align:left;
    font:40px MV Boli,rage;
}
img{
   width:330px;
   height:200px;
}
img.title{
   width:300px;
   height:150px;
}
img.center{
    display:block;
    margin-left:auto;
    margin-right:auto;
}
img.right{
    float:right;
    margin-left:15px;
    margin-bottom:15px;
}
img.header{
    border:none;
}
br{
    clear:right;
}
hr{
    border-style:outset;
    border-width:5px;
    border-color:#2c2a7b;
    background-color:#5b58dd;
    height:8px;
}
ol,ul{
    font:20px MV Boli;
    color:#b91e04;
}
ol.ur{
    list-style-type:upper-roman;
}
ul.sqaure{
    list-style-type:square;
}
a:link, a:visited, a:active{
        font: 25px MV Boli;
        color:#b91e04;
        text-decoration:none;
     }
a:hover{
    color:#ff0000;
    background-color:#ffffff;
    text-decoration:none;
}

</style>
</head>
<body>
<img  class="center" src="https://codehs.com/uploads/68062723f905589fc305a42ea5656f71" alt="states">
<h2>Table Of Contents:</h2>
<ul>
    <li><a href="#New York" target="_blank">New York</li>
    <li><a href="#Texas" target="_blank">Texas</li>
    <li><a href="#Florida" target="_blank">Florida</li>
    <li><a href="#Missouri" target="_blank">Missouri</li>
    <li><a href="#Nevada" target="_blank">Nevada</li>
    <li><a href="#South Carolina" target="_blank">South Carolina</li>
</ul>
<hr>
<img id="New York" class="title" src="https://codehs.com/uploads/45c83e7ad1cf07f3af75e91691c516e5"  alt="NY">
<a href="https://www.nyctourism.com/" target="_blank">
<img src="https://codehs.com/uploads/f5695fc9d423ace09ad9a0ca070bf632"  alt="NYflag" class="right">
<!--NY--><ul class="sqaure">
    <li>Governor</li>
        <ul class="sqaure">
            <li>Kathy Hochul</li>       
        </ul>
    <li>Motto</li>
        <ul class="sqaure">
            <li>Excelsior - "Ever upward"</li>              
        </ul>
    <li>Bird</li>
        <ul class="sqaure">
            <li>Eastern Bluebird</li>               
        </ul>
    <li>Tourist Attractions</li>
        <ul class="sqaure">
            <li class="check"><a href="https://www.niagarafallsstatepark.com/" target="_blank">
            Niagra Falls</li>
            </a>
            <li><a href="https://www.centralparknyc.org/" target="_blank">
            Central Park</li>
            </a>                
        </ul>
    <li>Capital</li>
        <ul class="sqaure">
            <li>Albany</li>             
        </ul>
</ul>       
<hr>
<img id="Texas" class="title" src="https://codehs.com/uploads/2a1cdee6893f401a0acf7968517023bb"  alt="Texas">
<a href="https://www.nyctourism.com/" target="_blank"><img src="https://codehs.com/uploads/f5695fc9d423ace09ad9a0ca070bf632"  alt="NYflag" class="right">
<!--Texas--><ul class="sqaure">
    <li>Governor</li>
        <ul class="sqaure">
            <li>Kathy Hochul</li>       
        </ul>
    <li>Motto</li>
        <ul class="sqaure">
            <li>Excelsior - "Ever upward"</li>              
        </ul>
    <li>Bird</li>
        <ul class="sqaure">
            <li>Eastern Bluebird</li>               
        </ul>
    <li>Tourist Attractions</li>
        <ul class="sqaure">
            <li class="check"><a href="https://www.niagarafallsstatepark.com/" target="_blank">
            Niagra Falls</li>
            </a>
            <li><a href="https://www.centralparknyc.org/" target="_blank">
            Central Park</li>
            </a>                
        </ul>
    <li>Capital</li>
        <ul class="sqaure">
            <li>Albany</li>             
        </ul>
</ul>       
<hr>
<img id="Florida" class="title" src="https://codehs.com/uploads/28c1e408541fbcfc2edbb476f120bfef"  alt="Florida">
<img src="https://codehs.com/uploads/f5695fc9d423ace09ad9a0ca070bf632"  alt="NYflag" class="right">
<!--Florida--><ul class="sqaure">
    <li>Governor</li>
        <ul class="sqaure">
            <li>Kathy Hochul</li>       
        </ul>
    <li>Motto</li>
        <ul class="sqaure">
            <li>Excelsior - "Ever upward"</li>              
        </ul>
    <li>Bird</li>
        <ul class="sqaure">
            <li>Eastern Bluebird</li>               
        </ul>
    <li>Tourist Attractions</li>
        <ul class="sqaure">
            <li class="check"><a href="https://www.niagarafallsstatepark.com/" target="_blank">
            Niagra Falls</li>
            </a>
            <li><a href="https://www.centralparknyc.org/" target="_blank">
            Central Park</li>
            </a>                
        </ul>
    <li>Capital</li>
        <ul class="sqaure">
            <li>Albany</li>             
        </ul>
</ul>       
<hr>
<img id="New York" class="title" src="https://codehs.com/uploads/b1bd68dae18f2838b208e1386f938331"  alt="NY">
<img src="https://codehs.com/uploads/f5695fc9d423ace09ad9a0ca070bf632"  alt="NYflag" class="right">
<!--Texas--><ul class="sqaure">
    <li>Governor</li>
        <ul class="sqaure">
            <li>Kathy Hochul</li>       
        </ul>
    <li>Motto</li>
        <ul class="sqaure">
            <li>Excelsior - "Ever upward"</li>              
        </ul>
    <li>Bird</li>
        <ul class="sqaure">
            <li>Eastern Bluebird</li>               
        </ul>
    <li>Tourist Attractions</li>
        <ul class="sqaure">
            <li class="check"><a href="https://www.niagarafallsstatepark.com/" target="_blank">
            Niagra Falls</li>
            </a>
            <li><a href="https://www.centralparknyc.org/" target="_blank">
            Central Park</li>
            </a>                
        </ul>
    <li>Capital</li>
        <ul class="sqaure">
            <li>Albany</li>             
        </ul>
</ul>       
<hr>
<img id="New York" class="title" src="https://codehs.com/uploads/b1bd68dae18f2838b208e1386f938331"  alt="NY">
<img src="https://codehs.com/uploads/f5695fc9d423ace09ad9a0ca070bf632"  alt="NYflag" class="right">
<!--Texas--><ul class="sqaure">
    <li>Governor</li>
        <ul class="sqaure">
            <li>Kathy Hochul</li>       
        </ul>
    <li>Motto</li>
        <ul class="sqaure">
            <li>Excelsior - "Ever upward"</li>              
        </ul>
    <li>Bird</li>
        <ul class="sqaure">
            <li>Eastern Bluebird</li>               
        </ul>
    <li>Tourist Attractions</li>
        <ul class="sqaure">
            <li class="check"><a href="https://www.niagarafallsstatepark.com/" target="_blank">
            Niagra Falls</li>
            </a>
            <li><a href="https://www.centralparknyc.org/" target="_blank">
            Central Park</li>
            </a>                
        </ul>
    <li>Capital</li>
        <ul class="sqaure">
            <li>Albany</li>             
        </ul>
</ul>       
<hr>
<img id="New York" class="title" src="https://codehs.com/uploads/b1bd68dae18f2838b208e1386f938331"  alt="NY">
<img src="https://codehs.com/uploads/f5695fc9d423ace09ad9a0ca070bf632"  alt="NYflag" class="right">
<!--Texas--><ul class="sqaure">
    <li>Governor</li>
        <ul class="sqaure">
            <li>Kathy Hochul</li>       
        </ul>
    <li>Motto</li>
        <ul class="sqaure">
            <li>Excelsior - "Ever upward"</li>              
        </ul>
    <li>Bird</li>
        <ul class="sqaure">
            <li>Eastern Bluebird</li>               
        </ul>
    <li>Tourist Attractions</li>
        <ul class="sqaure">
            <li class="check"><a href="https://www.niagarafallsstatepark.com/" target="_blank">
            Niagra Falls</li>
            </a>
            <li><a href="https://www.centralparknyc.org/" target="_blank">
            Central Park</li>
            </a>                
        </ul>
    <li>Capital</li>
        <ul class="sqaure">
            <li>Albany</li>             
        </ul>
</ul>       
<hr>

            
</body>
</html>

If anyone who knows how to make an internal link without it opening another tab and would like to share the knowledge I would appreciate it A LOT.

New contributor
Lizz is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

7

You can just remove the target="_blank" from your <a> tag.

<a href="#Texas">Texas</a>

target="_blank" tells the browser to open the link in a new tab, even when the link points to somewhere on the same page. Removing it keeps the navigation on the same page as intended.

Also, IDs can’t be accessed when they contain spaces. So use them like this instead:

<img id="New-York">

So your code would look something like this:

<ul>
  <li><a href="#New-York">New York</a></li>
  <li><a href="#Texas">Texas</a></li>
</ul>

<img id="New-York" src="example.png">
<img id="Texas" src="example2.png">
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.