Sylvain
Sylvain

Reputation: 3100

Best practices for POST/DELETE links on HTML

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:

Thanks :)

Upvotes: 0

Views: 314

Answers (1)

Domenic
Domenic

Reputation: 112917

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.

Upvotes: 0

Related Questions