The DOM property operation is to read, set, and remove the properties of the DOM element, such as prop (), Removeprop ().
1. Prop () 1.1 Get return value using Prop ()
Prop () returns the value of the first matching element when it returns a property value.
1<!doctype html>234<meta charset= "UTF-8" >5<title>prop () demo</title>6<script type= "Text/javascript" src= "Jquery.js" ></script>7<script>8$(function () {9 varCLA = $ ("div"). Prop ("class"));Ten Console.log (CLA); One A varid = $ ("div"). Prop ("id")); - Console.log (ID); - }) the</script> - -<body> -<div class= "Divclass" id= "divID" ></div> +</body> -1.2 Use prop () to set the property value 1.2.1 use Prop () to set a single property value1<!doctype html>234<meta charset= "UTF-8" >5<title>removeattr () demo</title>6<script type= "Text/javascript" src= "Jquery.js" ></script>7<script>8$(function () {9$ ("div"). Prop ("Class", "Divclass"));Ten$ ("div"). Prop ("id", "divid")); One }) A</script> - -<body> the<div></div> -</body> -The result of the execution is:
1.2.2 Setting multiple property values using prop ()1<!doctype html>234<meta charset= "UTF-8" >5<title>prop () demo</title>6<script type= "Text/javascript" src= "Jquery.js" ></script>7<script>8$(function () {9$ ("div"). Prop ({Ten"Class": "Divclass", One"id": "divID" A }) - }) -</script> the -<body> -<div></div> -</body> +The result of the execution is:
2. Removeprop ()return value: JQuery
Description: Deletes an attribute (property) for the matching element in the collection.
The syntax format is:
$ (selector). Remoceprop (PropertyName)
which
PropertyName
Type: string
The name of the property to remove
$ (selector). The Removeprop () method is used to delete the property value set by the $ (selector). Prop () method.
If you attempt to remove some of the built-in properties on the DOM element or the Window object, the browser may produce an error.
If you do, jquery first sets the property to undefined and ignores any browser-generated errors.
In general, you only need to remove the custom property, rather than removing the built-in (native) property.
Attention:Do not use this method to delete native properties, such as checked, disabled, or selected, which will completely remove the property. Once removed, it cannot be added to the element again.
2.1 Code Examples1<!doctype html>234<meta charset= "UTF-8" >5<title>removeprop () demo</title>6<script type= "Text/javascript" src= "Jquery.js" ></script>7<script>8$(function () {9 var$para = $ ("p");Ten One$para. Prop ("Luggagecode", 1234); A$para. Append ("The Secret Luggage Code is:", String ($para. Prop ("Luggagecode")), "."); -$para. Removeprop ("Luggagecode"); -$para. Append ("Now the Secret Luggage code is:", String ($para. Prop ("Luggagecode")), "."); the }) -</script> - -<body> +<p></p> -</body> +The result of the execution is:
Dom property manipulation of jquery property operations