Changing background color dynamically with jquery

后端 未结 3 1083
旧时难觅i
旧时难觅i 2021-01-29 05:27

Right now there is a part of my page that has a list of objects. When you hover over them, the background turns a light yellow color and return to white when you mouseout. I wan

3条回答
  •  -上瘾入骨i
    2021-01-29 06:07

    Try this :

    var bg = "#FFFFFF";
    if($myID.text() === schedule.content().myId) {
      bg = "#AEAF93";
    }
    $myID.css("background-color", bg);
    $stn.css("background-color", bg);
    $miles.css("background-color", bg);
    $worktag.css("background-color", bg);
    /*
    the above can be done in one line :
    $("#element1,#element2,#element3,#element4").css("background-color", bg);
    */
    $('#chevron').on('click', function() {
      $myID.css("background-color", bg);
      $stn.css("background-color", bg);
      $miles.css("background-color", bg);
      $worktag.css("background-color", bg);
    /*
    the above can be done in one line :
    $("#element1,#element2,#element3,#element4").css("background-color", bg);
    */
    });
    $sideBar.find('.myList').bind("mouseover", function(){
      $(this).css("background", "#fffccc");
    }).bind("mouseout", function(){
      $(this).css("background", bg);
    });
    

提交回复
热议问题