What is the recommended way to handle links that are used only for style and / or interactive purposes?

For example, the link below launches something in jQuery, but doesn’t go to another page, I used this method a while ago.

<a class="trigger" href="#"> Click Me </a>

Please note that there is only a hash tag and usually causes the page to skip when clicked, right? [I think]. This is only for interactive materials, does not go to another page or anything else. I see that many developers are doing this.

I feel this is wrong. Is there any other recommended way to do this without using HTML attributes, as it is not intended to be used?

Do not use <button>ether because the link will not be a button.

Maybe without a hash?

<a class="trigger"> Click Me </a>

& in CSS:

.trigger {
 cursor: pointer;
 }

So the user still knows what you want to click?

+3
4

.

, ( ) Firefox, Chrome, Opera Safari href (.. href="", href) , , hash-href, . Internet Explorer .

Internet Explorer href, , " " Windows. IE7 IE8 (IE6 , - ).

IE JavaScript, , ? , .

, href , .. , .. .


, @partoa , , , .

JavaScript , , , return false; . , , return false; , , , . preventDefault, (.. ). , , return false;, , .

+3

, false , , - . jQuery ,

$(selector).click(function(e)
{
    e.preventDefault();
});

HTML

<a class="trigger" onclick="return false;" href=""> Click Me </a>
+10

:

href= "#" , , , .

I recommend storing href = "#" in your tag and add return falseto the end of the script that is run by reference.

I see no reason why you would like to use the A tag for style purposes.

+2
source

in konqueror (kde browser), you can disable pointers to change. Then your decision will fail. But in general, I agree with you.

+1
source

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


All Articles