Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6548145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:54:57+00:00 2026-05-25T11:54:57+00:00

So as I am doing more and more web development I spend a lot

  • 0

So as I am doing more and more web development I spend a lot of time looking at the markup on other people’s pages. One thing that I have been tossing around is using anchors versus divs. Here is an example.

So I have some markup like this

<ul>
    <li>
        <div>
            <input type="hidden" value="#"/>
            div
        </div>
    </li>
    <li>
        <a href="#">anchor</a>
    </li>
</ul>

In the first instance I have a div with a hidden field that could contain a url to go to or a value to use in javascript. The next way is the same thing only I am using an anchor instead.

My css looks like this:

li {
    text-align:center;
    padding-bottom:5px;
}
div, a {
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    padding:2px 5px;
}
div {
    background: #aaa;
    color:#fff;
}
div:hover {
    cursor:pointer;
}
a{
    background: #777;
    display:block;
    text-decoration:none;
    color:#fff;
}

and my javascript looks like this:

$(function() {
    $('div, a').click(function(e) {
        e.preventDefault();
        alert('clicked');
    });
});

I have seen many pages that go for the first route with the div and use javascript to set the windows location via a hidden field. Is that correct or am I correct when I set the anchor’s style to block?

Also, on another semi-related note, instead of nesting an image inside an anchor to make an image link, I have started taking a different approach. I set the anchor to block, set a width and a height, and then set the background image. Is this approach correct and safe across all browsers?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:54:57+00:00Added an answer on May 25, 2026 at 11:54 am

    In general, anchors are used to jump the browser window to a specific part of the page, like so:

    http://www.example.com/#article-comments
    

    There is a definite target for the anchor tag, so one should be used.

    On the other hand, if you have a mail button:

    <div id="mail">Email</div>
    

    You’re not going to browse to the URL and expect the button to automatically trigger (it might, but that shouldn’t be something you’d expect to happen). Most of the buttons and links in Gmail’s interface are in fact <div>s, as anchors wouldn’t be appropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One thing I've started doing more often recently is retrieving some data at the
I've been trying to do more Web development work recently (I currently do other
I have been doing web development for more than 4 years. I have worked
This is more of a best practices question. I'm doing some front-end web development
Since I've started to use jQuery, I have been doing a lot more JavaScript
I read some website development materials on the Web and every time a person
I have been doing more client-side development, managing the UI on the client and
So im doing a bit of web development, and due to some restriction set
I am a programmer doing web development for over two years now. Even though
I'm working on an installer that, among other things, installs a web server. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.