0

this simple jquery .css statement does not activate within two functions, am I doing something wrong?

javascript:

function updateAllCSS(element, property, value) {

    function updateThemeCreatorCSS(element, property, value) {
        $(element).css(property, value)
    }
    updateThemeCreatorCSS(element, property, value)
}
}

updateAllCSS('h1', 'backgroundColor', '#f00')

HTML:

<h1>Test header</h1>
2
  • You need to quote your strings when you call updateAllCSS. Commented Sep 21, 2012 at 17:01
  • sorry that was just in this rewrite: it still doesnt work? Commented Sep 21, 2012 at 17:03

3 Answers 3

4

This should work:

function updateAllCSS(element, property, value) {
    function updateThemeCreatorCSS(element, property, value) {
        $(element).css(property, value)
    }
    updateThemeCreatorCSS(element, property, value);
}

updateAllCSS('h1', 'background-color', '#f00');

There was an extra } and the parameters being passed to updateAllCSS needed to have 'quotes'.

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

1 Comment

It works as backgroundColor as well. Hyphenated CSS properties can be referenced as camelCase in JavaScript.
3

You had an extra } and you should quote your parameters.

jsFiddle example

function updateAllCSS(element, property, value) {
    function updateThemeCreatorCSS(element, property, value) {
        $(element).css(property, value)
    }
    updateThemeCreatorCSS(element, property, value);
}
updateAllCSS('h1', 'backgroundColor', '#f00');​

Comments

2

Not sure why you have that nested function. Here's a Fiddle of it working:

http://jsfiddle.net/cbbdW/

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.