Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Links Anchors

Isaac Liao
Isaac Liao
908 Points

Link didn't go to the right place

~<a href="#some_text">My Link</a>

<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>

<p id="some_text">The anchor takes us here.</p>~

The anchor "my link" didn't go to the paragraph. Instead it links to the coding page in preview. I am not sure what happened.

5 Answers

Connor Hamilton
Connor Hamilton
5,023 Points

That doesn't explain much, can we see your HTML for the link and what its aiming to link towards.

I guess, this is what you are trying to implement: http://pastebin.com/CZzRGbRa

This : "The anchor "my link" didn't go to the paragraph. Instead it links to the coding page in preview. I am not sure what happened." is not clear to me though. Edited: ( I tried pasting the code here but it did not display properly so I used paste bin ).

Isaac Liao
Isaac Liao
908 Points

my code !<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>my page</title> </head>

<body>

<a href="#some_text">My Link</a>

<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>

<p id="some_text">The anchor takes us here.</p>

</body> </html>~

In preview, after I click on the hyperlink anchor, it didn't take me to the "id paragraph."

It took me to a page that shows below:

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>my page</title> </head>

<body> <blockquote cite="http://example.com/story.html"> <p> quick fox </p> </blockquote>

<p>A wise man once said <q>i think therefore i am</q></p>

<p>I know how to use <abbr title="self-contained under water breathign apparatus">Scuba</abbr> gear.</p>
<address>
    Nick Pettite<br>
    address <br>
    city
    country 
</address>

<p>My favoriate book is <cite>A Tale of Two Cities</cite></p>

<p>think<wbr>vitamin.com</p>

<dl>
    <dt>Video Pros</dt>
    <dd>Jon</dd>
    <dt>Teacher</dt>
    <dd>Jim</dd>
</dl>

<dl>
    <dt lang="en-US">color</dt>
    <dt lang="en-GB">colour</dt>
    <dd>A sensation drives from ability to life</dd>

</dl>


<a href="#some_text">My Link</a>

<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>

<p id="some_text">The anchor takes us here.</p>

</body> </html>

It looks like you have something else in your code that links you to that other page. I have tried the code you pasted above

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>My Page</title>
</head>

<body>
<a href="#some_text">My Link</a>

<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>

<p id="some_text">The anchor takes us here.</p>
</body>
</html>

and it is working fine. Would you mind pasting everything you have from the opening html tag to the closing part so we can get all the details about what is going on.

There is something I would like to note though, to go to the next line, you should use

<br />

or

<br>

should be alright. I don't think,

</br>

is correct though.

Aj Villalobos
Aj Villalobos
1,864 Points

Wierd. I tried that it works, maybe not enough space to move out?

Probably( what is your screen size?). But if you don`t have enough space, you should not get redirected to another page.

Isaac Liao
Isaac Liao
908 Points

Please see the complete html :

~<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>my page</title> </head>

<body>

<a href="#some_text">My Link</a>

<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>

<p id="some_text">The anchor takes us here.</p>

</body> </html>~

After click on "My Link," the browser shows

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>my page</title> </head>

<body>

<a href="#some_text">My Link</a>

<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>
<br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>

<p id="some_text">The anchor takes us here.</p>

</body> </html>