3

I want know if this script is bad, not working for me :

jQuery(".template_content_img").css({
    width: "50%",
    height: "150px",
    //// Here gives me error 
    font-size: "12px",
    margin-bottom: "23px",
});

I don´t know if the problem it´s is "width:200px" or "width","150px"

These are my dudes, by another side I see also many people use animate for this and no use css but why do you suppose the animate create effect and transformation of divs and by this only I need change somethings but it's not working.

Regards !!!

5
  • See the documentation. Commented Jun 20, 2013 at 2:12
  • 1
    Did you ever try .css({'width':50%, 'height':150px}) ? Commented Jun 20, 2013 at 2:15
  • @PSL - good but 50% or 150px is string so must be in quotes or apostrofs Commented Jun 20, 2013 at 2:22
  • @Shaddow oh yeah.. i din't notice... :) Commented Jun 20, 2013 at 2:25
  • @user2501504 Put the property keys in quotes. "font-size". Commented Jun 20, 2013 at 2:26

3 Answers 3

5

Check jQuery .css documentation

jQuery(".template_content_img").css({
    "width": "50%",
    "height": "150px"
});

jQuery(".template_img").css({
    "width": "70%",
    "height": "100px"
});

EDIT: If you want add font-size or margin-bottom, just use classic CSS attributes/values

jQuery(".template_content_img").css({
    "width": "50%",
    "height": "150px"
    "font-size": "12px",
    "margin-bottom": "23px",
});
Sign up to request clarification or add additional context in comments.

2 Comments

And one question how i can put this or use if i want put also for example othe things as fot-size , font-weight , margin-bottom , etc , thank´s for the help
just use classic CSS attributes/values
1

For multi-word CSS attributes, either use quotes:

"font-size": "12px",

or camelCase:

fontSize: "12px",

The object has to be a valid Javascript object literal, and delimiters like - are not allowed in unquoted property names.

1 Comment

+1 for having both options and the explanation.
0

You have to parse the css properties as a javascript Object using literals:

$('.class').css({
   width : '50%',
   height : '150px'
});

2 Comments

-1 irrelevant to the question
Because it completely fails to address the cause of the error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.