Using getStyle to return an style attribute value

Clicking the button will use getStyle method to get the background color of the blue element and pass it to the setStyle method, which will set the red element's background to the same color.

    x$('#box1').getStyle('background-color',function(value){
      x$('#box2').setStyle('backgroundColor',value);
    });

Using the addClass method

Clicking the button will add the red class to the empty white box. addClass checks to see if the class has already been applied and will not add duplicate classes to an element.

  x$('#box3').addClass('red');

Using the removeClass method

Clicking the button will remove the red class from the red box.

  x$('#box4').removeClass('red');

Using the css method

A nice shortcut to setStyle. It takes a JSON object of key/value pairs to set/change on an existing element. Click the button below to change the box properties.

x$('#box5').css({backgroundColor:'blue',width:'100px',border:'2px solid red'});