开发者

Is there anything wrong with having a button as a child element of an anchor?

开发者 https://www.devze.com 2022-12-12 10:35 出处:网络
I quickly tested t开发者_开发百科his in Firefox, and it seems to work <a href=\"somewhere\"><button>Go</button></a>

I quickly tested t开发者_开发百科his in Firefox, and it seems to work

<a href="somewhere"><button>Go</button></a>

The Validator didn't choke on it, but is it a reliable way to make a button a link?


Well, anchors are not necessarily links. This is why the validator doesn't choke. External anchors contain an HREF, sure, but internal anchors simply have a name attribute that can be referenced by placing #name in the URL.

Now, whether or not you should be placing a button in a link is another issue. The DOM uses event bubbling, so technically the button should respond to the click before the link does. But I do not know if this translates the same across all browsers.

0

精彩评论

暂无评论...
验证码 换一张
取 消