Most CSS manipulation is on an instance level where an object’s CSS property is modified.  If developer wish to manipulate a series of elements associating with a class, simple jQuery statement such as

$(“.someClassName“).css(“background-color”, “red”);

would do the trick.  The only problem is that if additional elements are introduced in the DOM in run-time, they would not reflect the new style.

There are two solutions.

1.  jQuery Live

jQuery Live watches run-time elements coming in and out of the DOM, and provides developers ways to handle specific situation.  However, setting up jQuery Live would require some work, and it may not be the fastest and most elogent solutions for manipulating CSS.

2.  jQuery Rule

This is basically getting down and dirty to CSS’s definition.  It allows direct manipulation of CSS Rule so the styles can instantly reflect on referenced elements.  This, however, may have quirkiness across browsers, but definitely the most straight-forward and fastest way.

Advertisements