Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css underline for anchor without href

Tags:

jquery

css

I have an <a id="javascriptlink"> tag, without href. Its action handled by jquery onclick. So, I want to put in css a:link {text-decoration: underline;} and a:hover {text-decoration: none;} to make it look like a link.

However, the anchor underline seems to only work when href attribute is presented. Any idea?

like image 766
Tom Avatar asked Jun 25 '12 06:06

Tom


People also ask

Can I have an anchor without href?

Yes, it is valid to use the anchor tag without a href attribute. 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.

How do you make an anchor tag without underline?

Complete HTML/CSS Course 2022 To remove underline from a link in HTML, use the CSS property text-decoration. Use it with the style attribute. The style attribute specifies an inline style for an element. Use the style attribute with the CSS property text-decoration to remove underline from a link in HTML.


2 Answers

Just add the href attribute but make the link do nothing by canceling the event.

<a href="#" onclick="event.preventDefault(); return false;" id="javascriptlink">
like image 69
iambriansreed Avatar answered Oct 05 '22 23:10

iambriansreed


a{
    text-decoration: underline;
    cursor: pointer;
}
a:hover{
    text-decoration: none;
}
like image 25
Dipak Avatar answered Oct 05 '22 21:10

Dipak