▪ ▪2015-09-23 20:01:47
css
▪ ▪, 2015-09-23 20:01:47

Button or link?

I'm wondering if the use of the "a" tag or the button button for links matters? But what if I, for example, use script activation when clicking on a link, for example, to open a dialog box? Would a link tag be appropriate here, or would a button be better?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2015-09-23
@kingdomofcrooked

There is nothing particularly malicious in the button - except that its support in IE6 is ill (but who needs it) and according to the layout rules it must sit inside the form, and the a tag is a dinosaur, 97% of primitive browsers know it, even the one on my old one Samsung'e (but Opera from version 2.1 0_o).
In general, why button ? You can click on everything.
But links are convenient because they implement the JS or PHP scheme - when clicking on the link, if the browser can work with JS (and it is not disabled), the script is executed, otherwise the request is to a PHP file (the current page, as a rule).

<a href="?catType=2" onclick="sortContent(event, 2)">
  Контент в виде таблицы
</a>
<a href="?catType=1" onclick="sortContent(event, 1)">
  Контент в виде постов
</a>

//Тем временем в JS
...
function sortContent(e, n){
   e.preventDefault();
   //code
}
...

But this is a rough example, of course.

A
Andrey Goncharov, 2015-09-23
@agmegadeth

button within the form is correct. Otherwise, the a tag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question