0

I have a form and its attributes.Now I have to add CSS dynamically to each attribute html attribute like text, textarea, checkbox, dropdown.

I also have another separate block which displays possible CSS attributes for adding CSS to form like font,font-style,width,padding for each html attribute. What is the best way of adding CSS to form via jquery. Mere adding normal CSS jquery like,

$( this ).css( "color", "red" ); 

to the form creates a lot of work. Is there any plugin in jquery that supports mainly for CSS related tasks. Or should I go with .css() jquery attribute itself. I need to add CSS to the form via inline. I will then save it.

4
  • can we provide your form html ? or a jsfidle Commented Sep 27, 2013 at 9:52
  • I have a seperate block for adding css. That block has many input boxes with each attribute like font-style,padding,width. Each time adding css to it using .css() will take a large script. Commented Sep 27, 2013 at 9:59
  • Yeah or a small and parameterized script. Commented Sep 27, 2013 at 10:00
  • 1
    Use like this $(this).css({ "color":"red", "font":"12px","width":"100px" }) Commented Sep 27, 2013 at 10:04

2 Answers 2

2

Have you consider this approach? :

$(this).addClass("classname");

It is much easier to manage CSS tags with this rather than using $(element).css many times.

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

Comments

1
$( this ).css( "color", "red" ). css("minWidth", "100%"); 

or

$( this ).css({ color : 'red', minWidth: '100' });

CssObject properties are the same as CSS properties but in camel case. Remove any - then transform in upper case the next letter, eg:

CSS property

border-bottom-width : 10px;

JQuery CSS Object Property

borderBottomWidth : '10px'

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.