max2020 max2020 - 24 days ago 6
Javascript Question

Javascript function with jquery css not functioning (No errors)

I have written a function that using jquery .css and simply passes the element, css property and the css value.

Here is the function:

function addCss(element, cssProperty, cssValue) {
$(element).css({ cssProperty: cssValue });
}


And here's an example usage:

addCss('.container','flex-direction', 'row');


For some reason its doing nothing.

I'm I missing something or is the syntax wrong?

Answer Source

Try $(element).css({ [cssProperty]: cssValue });