简体   繁体   中英

Attribute href not allowed on element button at this point

I have a problem with a button and the W3C validation; my code:

<button class="carousel-control left m-btn icn-only" href="#carousel_fade_2" data-slide="prev"><i class="icon-chevron-left"></i></button>

error w3c: Attribute href not allowed on element button at this point.

Any solution?

Thank you for your help.

href is not a valid attribute of the <button> element. A valid way would be to use a data-* attribute if you want to keep that value along with the button. For example:

<button
    class="carousel-control left m-btn icn-only"
    data-href="#carousel_fade_2"
    data-slide="prev">

If you want the browser to go to an anchor when clicking the button, you can use JavaScript to obtain the data-href value and update window.location.href with it, or you can use an <a> element instead, for which href is a valid attribute.

Buttons are used to submit forms. If you want to link somewhere, use an anchor:

<a href="#carousel_fade_2">

You can apply CSS to make it look like a button if you like.

href attricute is not used in the button element.

href is used in

<a href=""> LinkName </a>

or you can try this

<a href=""><button> Button text </button></a>

hope this helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM