JS Code
- $ ("Element"). attr (name) ' Gets the first matching property value, such as $ ("img"). attr ("src")
- $ ("element". attr (Key,value) ') ' an element setting property
- $ ("Element". attr ({key:value,key1:value,....})) ' Set multiple properties for an element at once
- $ ("element"). attr (key,function) ' Sets a computed property value for all matching elements.
- $ ("Element"). Removeattr (name)//Remove a property
JQuery Code:
$("img").attr("src");
Parameter Properties Description:
Set the SRC and ALT attributes for all images.
JQuery Code:
$("img").attr({ src: "test.jpg", alt: "Test Image" });
Parameter Key,value Description:
Set the SRC attribute for all images.
JQuery Code:
$("img").attr("src","test.jpg");
Parameter key, callback function Description:
Set the value of the SRC attribute to the value of the title property.
JQuery Code:
$("img").attr("title", function() { return this.src });
jquery element Property attr setting multiple key values or functions