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 trialJacob Lee
1,499 PointsAnchor tags wrapping elements
Is it semantically correct to wrap HTML elements such as divs and h tags with anchor tags as per the example?
3 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Jacob and welcome to Treehouse.
Yes it is. Whatever tag you wrap in an anchor tag will become part of the clickable area for the link. For example, if you are building a portfolio page, and you want the image and the description to be included in what can be clicked to go to the link, you would need to wrap the <img> and the <p> tags within the anchor tags.
Hope that answers your question. Keep Coding! :)
Jacob Lee
1,499 PointsGreat thanks for clarifying. Is that new to HTML5 as I'm sure is wasn't allowed in XHTML?
Jason Anders
Treehouse Moderator 145,860 PointsI'm really not that familiar with XHTML, so I can't answer that question, but it is perfectly okay in HTML5. :)
Unsubscribed User
8,841 PointsHi,
Per my understanding, if you have any button inside a division tag, then it wont work. To understand better, you can try out examples and check how it works.
The following discussion has information to your question.
http://stackoverflow.com/questions/1827965/is-putting-a-div-inside-an-anchor-ever-correct
Thanks, Aishu
Jacob Lee
1,499 PointsJacob Mishkin The example wrapped two <h> tags with a single <a> tag
<a href="index.html">
<h1>Heading 1</h1>
<h2>Heading 2</h2>
</a>
Jacob Mishkin
23,118 PointsI moved your comment to an answer so I could comment directly to your example, and yes Jason is right. if you click on either the h1 or h2 tags they both will have the same like which is index.html, and it is semantically correct. Jason said it best, and yeah this is okay to do.
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 Pointscan you give us an example? if it is some thing you saw in this video, I'm sure it is semantically correct.