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;
            }
        }

    }
5
  • have you set the border using javascript? Commented Jun 29, 2015 at 18:39
  • 1
    Show what you have done to set the border, and what have you tried to reset it Commented Jun 29, 2015 at 18:40
  • Quick google of your question title: does this help? stackoverflow.com/questions/3506050/… Commented Jun 29, 2015 at 18:41
  • I edited the post the question you @WeatherVane the question you say is not useful I have a particular setting in CSS. Commented Jun 29, 2015 at 18:49
  • why don't you use mousedown event for re setting ? Commented Jun 29, 2015 at 18:53

2 Answers 2

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
     });
});
Sign up to request clarification or add additional context in comments.

Comments

0

addClass / removeClass / or toggleClass ?

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

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

});

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

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

});   

Fiddler.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.