The prop() method sets or returns the properties
and values of the selected elements. When this method is used to return the
property value, it returns the value of the FIRST matched element. When this
method is used to set property values, it sets one or more property/value pairs
for the set of matched elements.
Syntex:
$(selector).prop(property) |
Example:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var $x = $("div");
$x.prop("color", "AA0000");
$x.append("The color property has the following value: " + $x.prop("color"));
$x.removeProp("color");
$x.append("<br>So Now the color property has the following value: " + $x.prop("color"));
});
});
</script>
</head>
<body>
<button>click here -> Add and remove a property</button><br><br>
<div></div>
</body>
</html>
|