0

So i have 2 JQuery .hover() one with function(){fname1(), fname2()} other one calling functions directly, why first work and second doesn't?

$(document).ready(on_ready())

function on_ready() {
    $('#h1main').hover(function () { on_hover() }, function () { on_hover_end() }) //WORK

    $('#h1main').hover(on_hover(), on_hover_end()) //DON'T WORK
}

function on_hover() {
    $('#h1main').css('color', 'red')
}

function on_hover_end() {
    $('#h1main').css('color', 'white')
}
  • The two arguments to `hover`, like the first argument to `setTimeout` in the duplicate question, need to be **functions**. You are calling `on_hover` and `on_hover_end` *immediately* and passing their return values (which happen to be `undefined` as they don't have `return` statements) to `hover`. – Quentin Oct 05 '22 at 13:01

0 Answers0