2013年4月14日 星期日

Modifying Object Properties and Attributes

The this.propertyName statement can be used to modify an object’s properties directly.

this means raw DOM object, but $(this) means jQuery object.

image

 

Object attributes can be accessed using attr()

image

 

.attr(attributeName, value) is the method used to access an object’s attributes and modify the value

image

Note that, jQuery will update all IMG titles in above example and no need to loop into each IMG tag.

 

To modify multiple attributes, pass a JSON object containing name/value pairs

image

 

Demo Example:

image

image

On the other hand, we can also using Object Chaining to get the same result.

image

沒有留言:

張貼留言