Is it more accessible to use <button> or <a> to open / close a modal?

In my opinion, buttons are used to perform functions, and links are used to move the user to another page. But what is best in terms of opening and closing a modal?

<a id="testModal" href="#">Open Modal</a>

or

<button id="testModal">Open Modal</button>
+4
source share
3 answers

<button>

Change <a href="#">to <button>and place an event handler on it.

Another context in which elements belong where ....

Does control control me on another page? Use binding

, ( ), URL ( ), <a href="[URL]">. , href URL-, "#" ( , , JavaScript, ). href "#", , , . , .

- ?

( ), ( , ..), <button>. <input type="button">, , (, ).

? Submit

, ( , ), , <input type="submit">. <form>. , , <button type="submit"> .

. , . , . , . , . , , , , , , .

, , , , , Enter , ( ).

+9

, .

  • ( ) , ( , : use , ).

  • url ( ajax , , , ). , , .

+2

- , . , . , . , . . .

(Ins + F7 JAWS), , . (Ctrl + Ins + B), , . , .

+2

Source: https://habr.com/ru/post/1649186/


All Articles