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

JavaScript

# hashtag before a link in a <a> elment in html but why?

hey guys, I'm rebuilding the Good Weather App and I was wondering why I need to add a hash tag at a link.

so this is my page

    <div data-role="page">
    <div data-role="panel" id="left-panel">
        <ul>
            <li>Close</li>
        </ul>
    <!-- panel content goes here -->
</div><!-- /panel -->    

and here is the link: <a href="#left-panel" data-icon="bars" data-role="button" data-iconpos="notext" data-iconshadow="false">Menu</a>

anybody has a hint for me?

3 Answers

They are called anchor tags, check out this simple short video on youtube which explains how it works pretty well.

https://www.youtube.com/watch?v=9TjkloW78UI

Alex Hedley
Alex Hedley
16,381 Points

I'm not sure if you mean the first or the second of my explanations.

If you want a link but don't want it to go anywhere, it's just a placeholder ATM you can use a # and it will stay on the page you are on instead of navigating to a particular page,

Or

If you have given an element an ID you can use a link to go to that part of the page using a hashtag and that id.

http://www.example.com/#section1

Where section1 is the id of a div (for example)

I see, so if I let the # and add some text to it, it will stay on the same page like I'd have a <a href="#">...