📜 ⬆️ ⬇️

On the use of links to run functions.

In the fashion struggle for the semantic purity of the code, we must abandon the practice of applying the following code:

<a onclick="doSomething()" href="#">Click!</a>

One article suggests instead the following jQuery code:

<a href="backuplink.html" class="doSomething">Click!</a>

$('a.doSomething').click(function(){ ... }

Yes, the HTML5 specification says: “The URL for hyperlink element must be valid. This URL is the destination of the hyperlink. ” But it turns out that when using a link to launch some AJAX loading of a part of the page, the link tag instead of what it was supposed to be used, starts the function. And the proposed option is also a link is not non-existent file specified.
')
Moral: to launch AJAX actions, use the BUTTONS and not the links.

Thanks for attention.

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


All Articles