Jquery basic notes three (DOM operation)

DOM manipulation

   1. Content operation

      1.html(): get/set the tag body content of the element

      2.text(): Get/set the plain text content of the element's tag body

      3.val(): Get/set the value attribute value of the element

    2. Attribute operations

       1. General attribute operations

             1.attr(): get/set the attributes of the element

             2.removeAttr(): delete attribute

             3.prop(): get/set the properties of the element

             4.removeProp(): delete property

                *The difference between attr and prop:

                       1. If the operation is the inherent properties of the element, it is recommended to use prop

                       2. If you are operating element-defined attributes, it is not recommended to use attr

         2. Operate the class attribute

             1.addClass(): add class attribute value

             2.removeClass(): delete the class attribute value

             3. toggleClass(): Switch the class attribute
                    * toggleClass("one"): 
                        * Determine if class="one" exists on the element object, delete the attribute value one. If class="one" does not exist on the element object, add
             4. css():

         3. CRUD operation:

             1.append(): The parent element appends the child element to the end

                *Object 1.append (object 2): add object 2 to the inside of the element of object 1, and at the end

             2.prepend(): The parent element appends the child element to the beginning

                *Object 1.prepend (object 2): add object 2 to the inside of the object 1 element, and at the beginning

             3.appendTo()

                *Object 1.appendTo (object 2): add the object 1 to the inside of the object 2, and at the end

             4.prependTo()

                *Object 1.prependTo (object 2): Add object 1 to the inside of object 2, and at the beginning

             5.after(): Add element to the back of the element

                *Object 1.after (object 2): add object 2 to the back of object 1, and object 1 and object 2 are brothers

             6.before(): add element to the front of the element

                *Object 1.before (object 2): Add object 2 to the front of object 1. Object 1 and Object 2 are brothers

             7.insertAfter()

                *Object 1.insertAfter (object 2): Add object 2 to the back of object 1. Object 1 and Object 2 are brothers

             8.insertBefore()

                *Object 1.insertBefore (object 2): Add object 2 to the front of object 1. Object 1 and Object 2 are brothers

              9.remove(): remove elements

                *Object.remove(): delete the object

              10.empty(): Empty all descendant elements of the element

                 *Object.empty() empties all descendant elements of the object, but retains the current object and its attribute nodes

 

Guess you like

Origin blog.csdn.net/SSbandianH/article/details/109799693