简体   繁体   中英

Javascript Jquery - Change Label Color

I have this code:

 jQuery('#novaPasse').on('keyup',function(){
            var pass = $(this).val();

            if (IsEnoughLength(pass) && HasMixedCase(pass) && HasNumeral(pass)){
                $('#forcaPasse').text('Palavra-Passe Muito Forte!');
                $('#forcaPasse').prev('label').css('color','#8EFA00');
            }else if (IsEnoughLength(pass) && HasMixedCase(pass)){
                $('#forcaPasse').text('Palavra-Passe Forte!');
                $('#forcaPasse').prev('label').css('color','#7CDB00');
            }else if (IsEnoughLength(pass) && HasNumeral(pass)){
                $('#forcaPasse').text('Palavra-Passe Moderada!');
                $('#forcaPasse').prev('label').css('color','#FC9C35');
            }else{
                $('#forcaPasse').text('Palavra-Passe Fraca!');
                $('#forcaPasse').prev('label').css('color','#FF0000');
            }
            });

The goal is to change the color along with the text. Without the color code it works and it changes the text. But I want the text differently colored.The text appears but the color doesn't change. This is my Label

<label id="forcaPasse"></label>

Does anyone know how to change the color of the font of the label?

The solution is: I removed prev('label')

jQuery('#novaPasse').on('keyup',function(){
            var pass = $(this).val();

            if (IsEnoughLength(pass) && HasMixedCase(pass) && HasNumeral(pass)){
                $('#forcaPasse').text('Palavra-Passe Muito Forte!');
                $('#forcaPasse').css('color','#8EFA00');
            }else if (IsEnoughLength(pass) && HasMixedCase(pass)){
                $('#forcaPasse').text('Palavra-Passe Forte!');
                $('#forcaPasse').css('color','#7CDB00');
            }else if (IsEnoughLength(pass) && HasNumeral(pass)){
                $('#forcaPasse').text('Palavra-Passe Moderada!');
                $('#forcaPasse').css('color','#FC9C35');
            }else{
                $('#forcaPasse').text('Palavra-Passe Fraca!');
                $('#forcaPasse').css('color','#FF0000');
            }
            });

Now it works correctly!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM