I just went through my current project and removed the extra ht...">

Why not allow the href attribute on non-anchor tags? - EG: <h1 href = ""> </h1>

I just went through my current project and removed the extra html and css where not needed, removing divs around abjects that don't need a div, for example, and I was wondering why we need agoras in everything:

<a href="Cake">
    <div>
        <p>This is not a lie.</p>
    </div>
</a>

      

Why not just allow:

<div href="Cake">
    <p>This is not a lie.</p>
</div>

      

+3


source to share


1 answer


I'm oversimplifying here, but this is about concepts.

In HTML, every tag has a meaning and function. Sometimes it's purely aesthetics ( <b>

, bold text), sometimes it's semantics ( <span>

, new chunk of inline text), sometimes both ( <h1>

, heading starts here). The point is to mark parts of the text with semantics.

A tag <a>

is a hyperlink. Almost everything in between <a>

and </a>

is assumed to behave like this: if clicked, navigate to a specific URL. This URL is now a property of the tag <a>

, and you specify it via href

.



This one href

doesn't make any sense outside of the tag <a>

, since since HTML, CSS and JavaScript have not existed, so you couldn't do things like create <span>

clickable like we can today. But even today, it doesn't make sense to allow elements to use the functionality of other elements, as this violates their semantics.

In your second example, you have completely removed the tag <a>

so it is no longer a link. Even if the parser resolves href

to div

, it would be wrong to suddenly make it behave like a tag a

, since it is not.

+5


source







All Articles