Jquery modifies the property value instance code of of to set the property value
- 2020-03-30 01:12:30
- OfStack
Set properties
- attr ()
The jQuery attr() method is also used to set/change property values.
The following example shows how to change the value of the href attribute in the link:
The instance
$("button").click(function(){
$("#keleyi").attr("href","//www.jb51.net");
});
The attr() method also allows you to set multiple properties simultaneously.
The following example shows how to set both the href and title attributes:
The instance
$("button").click(function(){
$("#keleyi").attr({
"href" : "//www.jb51.net",
"title" : " KeLeYi net "
});
});
The callback function for attr()
The following example demonstrates an attr() method with a callback function:
The instance
$("button").click(function(){
$("#keleyi").attr("href", function(i,origValue){
return origValue + "/jquery";
});
});