The this.propertyName statement can be used to modify an object’s properties directly.
this means raw DOM object, but $(this) means jQuery object.
Object attributes can be accessed using attr()
.attr(attributeName, value) is the method used to access an object’s attributes and modify the value
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
Demo Example:
On the other hand, we can also using Object Chaining to get the same result.
沒有留言:
張貼留言