In jquery, you can use the attr() method to add an id to an element; this method can add specified attributes to the element and set the specified attribute value. You only need to set the value of its first parameter to " id", the second parameter can be set to the specified id value, the syntax is "specified element object.attr("id","specified id value")".
The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.
In jquery, you can use the attr() method to add an id to an element.
attr() method can add specified attributes to elements and set specified attribute values.
This method accepts two parameters:
$(selector).attr(attribute,value)
Parameters | Description |
---|---|
##attribute | Specifies the name of the attribute.|
value | Specifies the value of the attribute.
attributesof the method to
id, the second parameter
valuecan be set to the specified id value.
jQuery video tutorial,web front-end video]
The above is the detailed content of How to add id to element in jquery. For more information, please follow other related articles on the PHP Chinese website!