g(..).setStyles(styleName, val, [styleName2, val2, styleName3, val3, etc..])

Simliar to .setStyle, but allows you to set multiple styles at once, alleviating the need to chain together multiple .setStyle(..) calls.

Returns: Itself (the same Gimme Object is returned so additional methods can be chained together seamlessly).
  • styleName, required: a string specifying the style property to be set (ex: 'backgroundColor').
  • val, required: a string value to be assigned to .style[styleName] property.
  • styleNameN, optional: same as the styleName param.
  • valN, optional: same as the val param.

// for all <p> elements with the class "funny", sets: opacity = .5, border = '5px solid red', and background = 'pink'
g('p.funny').setStyles('opacity', .5, 'border', '5px solid red', 'backgroundColor', 'pink');

// for all <div> elements with the class "patriotic", sets: color = 'white', backgroundColor = 'blue', border = '5px solid red'
g('div.patriotic').setStyles('color', '#fff', 'backgroundColor', '#00f', 'border', '5px solid #f00');

Additional Information:
There is little to no efficiency gain over chaining together multiple .setStyle(..) calls together. The .setStyles(..) method is more available just for convenience and readability.

It's also worth noting that the number of parameters passed into the method must be even. If this is not the case, the entire call will be considered invalid and discarded.

Last edited Nov 13, 2007 at 7:42 PM by sstchur, version 1


No comments yet.