1

is there any better way?

$("< style >").attr("type","text/css").prependTo("head").append(".bor {border:2px dotted red} .gto {padding:10px; font-size:medium}");

$("input:text").addClass("bor gto").val("your text");

http://jsfiddle.net/adatepe/aLmc2/

1
  • 2
    Is there a reason you are doing it this way as opposed to having a CSS file already built? Commented Apr 25, 2011 at 17:55

2 Answers 2

1

Maybe you could set the CSS directly rather than trying to build CSS classes at runtime:

$('input:text').css({
    border: '2px dotted red',
    padding: '10px',
    fontSize: 'medium'
}).val('your text');
Sign up to request clarification or add additional context in comments.

Comments

0

If by any chance you need to do this way why not do it the simple way then?

$("<style type='text/css'>.bor {border:2px dotted red}" + 
  " .gto {padding:10px; font-size:medium}</style>").prependTo("head");

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.