简体   繁体   中英

How do I remove the text underline (that I set myself) from a <span> on hover?

I want to have a link but I want to have a jQuery event fire onclick so I am using a <span> with an id instead of a link so I can listen for the click event.

I want to make the <span> look like a link so:

  1. The cursor should show a hand when the <span> is hovered
  2. The <span> should be underlined and blue

This works fine in CSS, but I want to remove the underline when I hover. How would I do this in CSS?

span:hover {
    text-decoration: none;
}

"i want to have a link but i want to have jquery event fire onclick so i am using a span instead of a link"

Why not just place the click event on the <a href='whatever'> ?

  // Use the actual ID instead of 'a'.
$('a').click(function( event ) {
    event.preventDefault(); // Prevent the link from being followed
    // do something
});

Then change the text-decoration of the <a> on using the pseudo :hover

a:hover {
    text-decoration:none;
}

If you do it on a <span> instead, the :hover won't work in IE6.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM