Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fade in text-decoration css with jquery?

I have the following code:

This is a <span id="sentence">sentence</span>.

When a user hovers over sentence, I would like an underline to fade in under the word.

This seems like such a simple problem, but I have not been able to figure out how best to do it. Just to be clear, I cannot just use css:hover. I need to do this with JQuery given the actual problem is more complicated and requires more control than that illustrated here. Thanks very much for your help in advance.

like image 895
Andrew Avatar asked Dec 08 '12 06:12

Andrew


1 Answers

This might not fit your needs, and I realize you specifically don't want to use CSS. But just in case...

HTML

This is a <span id="sentence">sentence.</span>​

CSS

span {
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
    transition: all 0.5s;
    border-bottom: 1px solid transparent;
}

span.clicked {
    border-bottom: 1px solid black;
}​

Script

$('span').click(function(){
  $(this).addClass('clicked');
});

http://jsfiddle.net/as42u/4/

like image 66
Chris Herbert Avatar answered Sep 19 '22 12:09

Chris Herbert