1

Trying to use css in jquery to define an element and another snipet of code when the mouse hovers over, i cant get either css codes to run. This is a proposing experiment and already aware CSS is more of use. This is simply a jquery use only codes.

Here are the jquery codes for a given paragraph with class p.

<p class="p"> this is a generic element with generic coding.</p>

Here is the jquery end.

$("document"). ready( function (){
    var $p = $("p.p");

    $p
        .css({
            "font-size" :  "200%" ,
            "color" : "#030"
        })
       .onhover( function(){
            $p.css({
                "font-size" : "175%" ,
                "color" : "#060"
            });
      });
});

Hopefully it will work! Thank you all for your hard work!

5
  • is onhover a jQuery function? what i know is jQuery.hover() Commented Jul 6, 2016 at 23:08
  • it was i think, its suppose to be for when a mouse hovers over it Commented Jul 6, 2016 at 23:09
  • .onhover should be .on("mouseover",function(){... Commented Jul 6, 2016 at 23:10
  • Any reason you don't want to just do this with CSS? Commented Jul 6, 2016 at 23:20
  • because i am proposing an experiment on the efectiveness on jquery using both javascript and css. vs css alone (which i can easily do, but it will defeat the purpose of this experiment) Commented Jul 6, 2016 at 23:23

1 Answer 1

1

As i mentionned in comment, there is no onhover in jQuery. Maybe in raw javascript but you cannot use it that way and apply it to jQuery object.

Use jQuery.hover() instead:

$("document"). ready( function (){
    var $p = $("p.p");

    $p
        .css({
            "font-size" :  "200%" ,
            "color" : "#030"
        })
       .hover( function(){
            $p.css({
                "font-size" : "175%" ,
                "color" : "#060"
            });
      });
});

Or you can use jQuery.on("mouseover", callback) as suggested by Louys. The two approaches serve your purpose for chainability.

Sign up to request clarification or add additional context in comments.

17 Comments

Does .hover needs two handler ? If only one specified, it's the out handler??? I'm not sure but...
tried the input on w3schools try it yourself. still not seeing any css on any event
@LouysPatriceBessette I don't see what you mean honneslty!
@LouysPatriceBessette, it is only one callback.
JsFiddle of the above much better than W3Schools .... note that Document.Ready is handled by jsfiddle
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.