javascript - jquery - change text color - Stack Overflow

I'm new to Jquery and I'm trying to get started by simply changing the color of the font when

I'm new to Jquery and I'm trying to get started by simply changing the color of the font when I hover over it. I thought that I put the right code in but it's not working? can someone help me get this going?

SHOW.JS:

$(document).ready(function(){
 $(".modal").hover(function(){
 $(".modal").css("color","red");
}));

SHOW.HTML.ERB:

 <p class="modal"><%= @subscriber.last_name %></p>

APPLICATION.JS:

 //= require jquery
 //= require jquery_ujs
 //= require turbolinks
 //= require_tree .

This is all my code. I just wanted to keep it simple at first.

I'm new to Jquery and I'm trying to get started by simply changing the color of the font when I hover over it. I thought that I put the right code in but it's not working? can someone help me get this going?

SHOW.JS:

$(document).ready(function(){
 $(".modal").hover(function(){
 $(".modal").css("color","red");
}));

SHOW.HTML.ERB:

 <p class="modal"><%= @subscriber.last_name %></p>

APPLICATION.JS:

 //= require jquery
 //= require jquery_ujs
 //= require turbolinks
 //= require_tree .

This is all my code. I just wanted to keep it simple at first.

Share Improve this question edited Jul 6, 2016 at 2:04 Bitwise asked Jul 6, 2016 at 2:01 BitwiseBitwise 8,46125 gold badges80 silver badges177 bronze badges 4
  • 1 Have you included the jQuery library ? Do share browser-rendered code instead of ruby code... – Rayon Commented Jul 6, 2016 at 2:02
  • I think so. I'm posting the file (UPDATED) – Bitwise Commented Jul 6, 2016 at 2:03
  • Any errors? What's the current behavior? – Petr Gazarov Commented Jul 6, 2016 at 2:09
  • Possible duplicate of How can I change the text color with jQuery? – Martin Thoma Commented Jul 27, 2017 at 7:26
Add a ment  | 

3 Answers 3

Reset to default 2

Andros Rex's method works perfectly - however you may actually want something more like this instead - it changes the color back to the previous color when the mouse is no longer over the element.

$(document).ready(
    function() {
        var old;
        $(".modal").hover(
            function() {
                old = $(".modal").css("color");
                $(".modal").css("color","red");
            },
            function() {
                $(".modal").css("color",old);
            }
        );
    }
);

There are missing closing parentheses. This is how it should be:

$(document).ready(function() {
  $(".modal").hover(function() {
    $(".modal").css("color","red");
  });
});

Try this

$('.modal').css({"color" : "red"});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742339090a4425254.html

相关推荐

  • javascript - jquery - change text color - Stack Overflow

    I'm new to Jquery and I'm trying to get started by simply changing the color of the font when

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信