1

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.

Bitwise
  • 8,021
  • 22
  • 70
  • 161

3 Answers3

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);
            }
        );
    }
);
Tibrogargan
  • 4,508
  • 3
  • 19
  • 38
1

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

$(document).ready(function() {
  $(".modal").hover(function() {
    $(".modal").css("color","red");
  });
});
Andros Rex
  • 372
  • 1
  • 7
1

Try this

$('.modal').css({"color" : "red"});
Fer VT
  • 500
  • 1
  • 8
  • 25