In JQuery, Is it possible to get callback function after setting new css rule?

后端 未结 6 1101
一生所求
一生所求 2020-12-03 17:05

I have $(\'.element\').css(\"color\",\"yellow\") and I need that next event was only after this one, something looks like $(\'.element\').css(\"color\",\"

6条回答
  •  眼角桃花
    2020-12-03 17:29

    Callbacks are only necessary for asynchronous functions. The css function will always complete before code execution continues, so a callback is not required. In the code:

    $('.element').css('color', 'yellow');
    alert(1);
    

    The color will be changed before the alert is fired. You can confirm this by running:

    $('.element').css('color', 'yellow');
    alert($('.element').css('color'));
    

    In other words, if you wanted to use a callback, just execute it after the css function:

    $('.element').css('color', 'yellow');
    cb();
    

提交回复
热议问题