Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change text color in jquery animate?

Tags:

html

jquery

I am very new to jquery. I am trying to change text color using jquery animate. But my code is not working. please anyone help me

<script>
$(p).hover(function(){
    $(this).animate({"color":"red"})
    })
</script>
like image 766
alon1234 Avatar asked Jun 01 '13 11:06

alon1234


People also ask

How can I change the text color with jQuery?

To change the text color with jQuery, use the jQuery css() method. The color css property is used to change text color.

Can you animate background color in jQuery?

The background color animate can be performed with the help of the animate() function or css() function. The background color animate is used to set the background color of the selected elements.

Is jQuery good for animation?

The jQuery library provides several techniques for adding animation to a web page. These include simple, standard animations that are frequently used, and the ability to craft sophisticated custom effects.


2 Answers

Without using any additional plugin: I know this question is pretty old now but this is to help anyone still looking for a solution... here is a workaround without the need of any additional plugin.

jQuery css to change the color:

$("p").hover(function(){
    $(this).css("color","red");
})

and CSS transition to replicate the animation effect when the color changes:

p {
color: black;
-webkit-transition: color 0.4s ease;
-moz-transition: color 0.4s ease;
-o-transition: color 0.4s ease;
transition: color 0.4s ease;
}
like image 78
Rishabh Rajgarhia Avatar answered Oct 05 '22 22:10

Rishabh Rajgarhia


You can simply acheive it with Jquery UI. After adding simply

$( "#effect" ).animate({
          backgroundColor: "#aa0000",
          color: "#fff",
          width: 500
        }, 1000 );

http://jqueryui.com/animate/

like image 35
Suresh Atta Avatar answered Oct 06 '22 00:10

Suresh Atta