This example describes the jquery node element attribute operation method. Share to everyone for your reference. The specific analysis is as follows:
In jquery, the attr () method is used to get and set the element properties, Removeattr () method to delete the element attributes.
Getting properties and setting properties
If you want to get the property title of the P element, you only need to pass a parameter to the attr () method, which is the property name.
var $para = $ ("P"); Get <p> node
var p_txt = $para. attr ("title");//Get <p> element node property title
If you want to set the value of the property title of the <p> element, you can also use the same method, and the difference is that you need to pass two arguments, namely the property name and the corresponding value.
$ ("P"). attr ("title", "Your title");
To set individual property values
If you need to set multiple properties for the same element at once, you can use the following code to implement:
$ ("P"). attr ({"title": "Your title", "Name": "Test"});
Sets an object of type "name/value" to the property of the matching element
Many of the methods in jquery are the same function implementation fetch (getter) and set (setter), such as the attr () method above, which can either set the value of the element property or get the value of the element property. Similarly, there are methods such as HTML (), text (), height (), Width (), Val (), and CSS ().
Delete attribute
In some cases, you need to remove specific attributes for an element in a document, and you can use the Removeattr () method to complete the task.
If you need to remove the title attribute of the P element, you can use the following code to implement:
$ ("P"). Removeattr ("title");
Delete the attributes of the <p> element title
You can see it very clearly under the Firebug.
I hope this article will help you with your jquery programming.