JQuery implements P tag operations
Note: The following code has passed the W3School online test.
Method for retrieving the element itself (Object) based on the id:
$ (# Id );
For example:
<Script src =/jquery/jquery-1.11.1.min.js> </script> <script> $ (document ). ready (function () {$ (p ). click (function () {alert ($ (# p1) ;}); </script>
If you click me, I will disappear.
Click me and I will disappear.
Click me.
Running result:
Method for retrieving the element itself (Object) based on the class:
<Script src =/jquery/jquery-1.11.1.min.js> </script> <script> $ (document ). ready (function () {$ (p ). click (function () {alert (obtains the element itself based on the class: + $ (. class1) ;};}); </script>
If you click me, I will disappear.
Click me and I will disappear.
Click me.
Running result:
To obtain the P tag text content, follow these steps:
Method 1: $ (# p1). text ();
Method 2: Certificate (#p1).html ();
For example:
<Script src =/jquery/jquery-1.11.1.min.js> </script> <script> $ (document ). ready (function () {$ (p ). click (function () {alert (text () method: + $ (# p1 ). text (); alert (html () method: Plain plain (#p1).html () ;}); </script>
If you click me, I will disappear.
Click me and I will disappear.
Click me.
Running result:
$ (# P1). text (); method:
((#P1).html (); method:
How to Get attributes:
$(this).attr(id)
For example:
<Script src =/jquery/jquery-1.11.1.min.js> </script> <script> $ (document ). ready (function () {$ (p ). click (function () {alert (name attribute value in the P Tag: + $ (this ). attr (name); alert (class Attribute Value in the P Tag: + $ (this ). attr (class); alert (id attribute value in the P Tag: + $ (this ). attr (id) ;}); </script>
If you click me, I will disappear.
Click me and I will disappear.
Click me.
Running result:
Get the name property:
Get class attributes:
Get id attributes: