Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it correct to use div tag inside anchor tag?

Tags:

html

jsp-tags

I have used the following piece of code where I have used div tag inside anchor tag. The code is working fine but I am not sure if this is the correct format. Is it correct to use div inside anchor tag ?

<a class="discount-popup" href="#" id="WC_Link_ProductDiscount_1_<c:out value="${discountCounter.count}"/>">
    <div id="view_offer" style="display: block;">
        &nbsp;&nbsp;<u style="color: #000000;"><c:out value="View offer details" escapeXml="true" /></u>
    </div>
    <div id="offer_details" style="display: none;">
        <c:out value="${calculationCodeDBs[0].longDescriptionString}" escapeXml="false" />
    </div>
</a>
like image 333
Rajanya Ghosh Avatar asked Dec 28 '25 19:12

Rajanya Ghosh


2 Answers

In HTML5 you can. In previous versions of HTML you can't. To make this code valid you need to set the correct doctype:

<!DOCTYPE html>

With this doctype the browser identifies HTML5 page. Put it before <html> tag.

like image 163
Marcos Pérez Gude Avatar answered Dec 30 '25 12:12

Marcos Pérez Gude


Yes, its fine to you use DIV elements inside an anchor tag, but you will need to setup your CSS correctly for each one (height, width, display, etc), otherwise, the height will revert to the line height by default.

Hope this helps.

like image 35
williamtroup Avatar answered Dec 30 '25 12:12

williamtroup