Hi. My knowledge of javascript are limited and I bumped into a simple thing today , but it seems that I can get it done. I've got a javascript file , and to the top of this I have something like: var options = { "background":{ "colour":"red", "pattern":"lines" }, "text":{ "style":"bold", "arrange":"middle" } }; Code (markup): So , what I'm trying to do is to take each key's value: Eg. options -> background -> colour and I should get "red". It works well if I use with an alert like: alert(options.background['colour']); Code (markup): but how would I get that value to this (eg. flexslider's atributes ) : $('#blog-slider').flexslider({ slideshow: true, background: "red" // where 'red' will be the value from options.background['colour'] }); Code (markup): (There's no attribute for flexslider "background" , but is just an example) Probably it's a simple thing , but a little help will be great.
$('#blog-slider').flexslider({ slideshow: true, background: options.background.colour }); Code (markup): ... or am I something missing? PS: calling the var colour = options.background.colour; Code (markup): is the same as var colour = options.background['colour']; Code (markup): there is no reason to write code like in second example
one more thing. To play with javascript press: Ctrl+Shift+J javascript console will pop up (in firefox and chrome) and you can play with javascript and learn how things works. keep it up, don't give up God Bless
Pls adjust your options object to some thing like this var options = { background: { colour: "red", pattern: "lines" text: { style: "bold", arrange: "middle" } Code (markup): to give your $('#blog-slider') jquery object the red options property, do it like this $('#blog-slider').prop(flexslider).prop(background) = options.background.color; Code (markup): NOTE: you use the prop() function to access jquery object properties. hope this helps
I can't get options object like this, because it's generated automatically by a WordPress function (wp_localize_script) inside the <head></head> tags and I can't edit this. Thanks both for your answers , I've managed to do this. The problem seemed to be in a php array that was generating this object.