Attributes in jQuery
Some of the most basic components, we can manipulate DOM elements, are properties and attributes assigned to those elements.
Most of these attributes are available through JavaScript as DOM node attributes. Some of the more common attributes are:
- className
- tagName
- id
- href
- title
- rel
- src
Consider the following HTML code fragment for an image element:
id = "imageid" src = "image.gif" alt = "Image" class = "myclass" title = "This is an image" />
In marking this element, the tag name is img, and the markup for id, src, alt, class, and title represents the properties of the element, each with a name and a value.
jQuery provides us with methods to manipulate element properties easily and help us access these elements so that we can change their properties.
Get attribute values in jQuery
The attr () method can be used to get the value of an attribute from the first element in the matched set or set the attribute values on the matched elements.
For example
The following is a simple example that takes the title attribute of the tag and sets the value
The jQuery Example
You should read it
Maybe you are interested
AMD has surpassed Intel in brand value
SQL way to count NULL and NOT NULL values in a column
Comparing Odroid-N2+ and Raspberry Pi 4: Which option offers better value?
How to receive free gifts from IObit with a total value of nearly 150,000 USD
Write a program to find duplicate values in Python
Write a program to check duplicate values in Python