Changing background color dynamically with jquery

后端 未结 3 1089
旧时难觅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条回答
  •  执念已碎
    2021-01-29 06:18

    Finally found my answer to this.

    CSS

    .highlightedClass{
        background-color: #AEAF93;
    }
    

    JAVASCRIPT

                    //if condition      
                            if($td_ID.text() === schedule.content().idInFirstColumn){
                                    $2nd_tr.addClass("highlightedClass");                       
                            }else{
                                if($2nd_tr.hasClass("highlightedClass")){
                                    $2nd_tr.removeClass("highlightedClass");
                                }
                            }
    
                            $('#viewResultsButton').on('click', function(){
                                if($td_ID.text() === schedule.content().idInFirstColumn){
                                    $2nd_tr.addClass("highlightedClass");   
                                }else{
                                    if($2nd_tr.hasClass("highlightedClass")){
                                        $2nd_tr.removeClass("highlightedClass");
                                    }
                                }
                            });
    
    
                    //else condition
                            if($td_ID.text() === schedule.content().idInFirstColumn){
                                    $tr.addClass("highlightedClass");                       
                            }else{
    
                                if($tr.hasClass("highlightedClass")){
                                    $tr.removeClass("highlightedClass");
                                }
                            }
    
    
    
    
        //outside of huge if/else/for loop mess.
    
        $('#viewResultsButton').on('click', function(){
            var flag= false;
            $('#alteratePlan > tbody  > tr').each(function() {
                $td_ID = $(this).find('.td_id');
                if($td_ID.text() === ''){
                    if(flag === true){
                        $(this).addClass("highlightedClass");
                        flag= true;
                    }
                }else{
                    if($td_ID.text() === schedule.content().idInFirstColumn){
                        if($(this).hasClass("highlightedClass")){
                            flag= true;
                        }else{
                            $(this).addClass("highlightedClass");
                            flag= true;
                        }
                    }else{
                        flag= false;
                        if($(this).hasClass("highlightedClass")){
                            $(this).removeClass("highlightedClass");
    
                        }
                    }
                }
    
            });
        });
    

提交回复
热议问题