0

Is there a way to reset the settings of css for an element? i have an input that I want validate and is not possible because I set the border of text input red but I can't come back to the settings of CSS automatically. is there a way for do it? thanks in advance.

EDIT 1

<input id="tm" type="text" onchange="validateStartTime()" name="orario_start" placeholder="Orario inizio">

and validateStartTime() is

 function validateStartTime(){

        var t_st=document.getElementsByName("orario_start");
        t_st[0].style.borderColor="gray";//HERE I want to set back to the CSS settings automatically
        if(t_st[0].value.length==0){
            t_st[0].style.borderColor="red";
            flag=false;
        }
        //validation time
        var t1=t_st[0].value.split(" ");
        if(t1.length!=2){
            t_st[0].style.borderColor="red";
            flag=false;
        }else{

        var t1_1=t1[0].split(":");
            if(t1_1.length!=2){
                t_st[0].style.borderColor="red";
                flag=false;
            }
        }

    }
Dr Upvote
  • 8,023
  • 24
  • 91
  • 204
Alexander.It
  • 187
  • 1
  • 1
  • 16

2 Answers2

1

Hi If you are using jQuery than you can simply change CSS directly :

$('#yourElementId').css({
    border : 1px solid #ff0000
});

If you are facing issue of removing that red border again than onmousedown you can remove that border.

 $('#yourElementId').mousedown(function(){
     $(this).css({
       border : 1px solid white
     });
});
Anshul
  • 9,312
  • 11
  • 57
  • 74
0

addClass / removeClass / or toggleClass ?

$( '#add' ).click( function () {

    $( '#page_navigation1' ).addClass( 'red-class' );

});

$( '#remove' ).click( function () {

    $( '#page_navigation1' ).removeClass( 'red-class' );

});   

Fiddler.

Dr Upvote
  • 8,023
  • 24
  • 91
  • 204