1
<style type="text/css">
 .style1
  {
      border:2px solid #e53a6f;
      box-shadow:0 0 5px 0 #e53a6f;
  }
</style>

javascript

 <script type="text/javascript" language="javascript">
 if (Pname == "")
 {
  document.getElementById('<%=txtname.ClientID %>').style.border="2px solid  #e53a6f";                                         
       return false;
  }

 </script>

I am new to css. My question is I want to call style1 css instead of calling .style.border="2px solid #e53a6f";in java script . Is this possible?. Can some one help me out.

2
  • do you want to call certain styles from 2 diffrent style sheets or from a style in your header section becuase if you want to change it using styles in your header section you could just use funktions and call the funktion with diffrent styles in it but if you want to call a style from a diffrent style sheet thats a diffent queestion Commented Sep 15, 2013 at 15:30
  • im not sure exactly what you want correct me if im wrong . you want to change the style the element is refrencing to from a stylesheet using javascript. so you need 2 diffrent styles in your style sheet then your javascript must change the style attribute of the element? Commented Sep 15, 2013 at 15:38

2 Answers 2

3

you can try document.getElementById('<%=txtname.ClientID %>').className = 'style1';

Sign up to request clarification or add additional context in comments.

Comments

2

You could try assigning the proper CSS class to the DOM element using the className property:

document.getElementById('<%=txtname.ClientID %>').className = 'style1';

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.