The element a must not appear as a descendant of the button element

邮差的信 提交于 2019-12-05 07:49:33

The Error Message have Answered Your doubt Already According to HTML5 Spec Documentation

you can nest any elements inside an <a> except the following:

<a>

audio> (if the controls attribute is present)

<button>

<details>

<embed>

<iframe>

<img> (if the usemap attribute is present)

<input> (if the type attribute is not in the hidden state)

<keygen>

<label>

<menu> (if the type attribute is in the toolbar state)

<object> (if the usemap attribute is present)

<select>

<textarea>

<video> (if the controls attribute is present)

So you need to use some css to design an Button (or there is many Methods) instead of adding Button inside a element.

The usual error from the W3C validator is:

The element button must not appear as a descendant of the a element

This makes more sense for your question, as you have a button that is a descendant of an anchor.

Normally, you could solve the issue by simply styling your anchor tag, or by placing the button within a form element:

<form style="display: inline" action="http://www.example.com/" method="get">
  <button>Some Call to Action</button>
</form>

But in your case, I don't think you even need the anchors as you aren't linking anywhere using HTML (and if you are attaching events using JavaScript, you could simply attach those events to the button rather than the anchor.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!