max2020 max2020 - 6 months ago 45
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 });

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download