Best practices for POST/DELETE links on HTML

283 views Asked by At

I don’t want to use GET method for some destructive links (like deleting an item, remove something…) so I use POST or DELETE actions on my links, with a Javascript AJAX request like this:

<a class="js-link" data-method="DELETE" data-confirmation="Are you sure?" data-href="xxx">

I don't use href because the URL is not available with a GET method (error 405).

My questions are:

  • What are the best-practices for these kind of links?
  • Is this valid HTML?
  • What about users without JS, old browsers?

Thanks :)

1

There are 1 answers

0
Domenic On

As mentioned in the comments, the appropriate solution here is to use a <button> or similar. Since these are not hypertext links that you can follow, which can be followed by e.g. search engine crawlers, they should not be represented using the <a> hypertext anchor element.

Note that according to the standard:

If the a element has no href attribute, then the element represents a placeholder for where a link might otherwise have been placed, if it had been relevant, consisting of just the element's contents.

so your usage of href-less <a> does not match the standard's definition.