In jQuery, the attr()
method is used to set or return the value of an element. To get the individual value for each element, a looping construct, such as jQuery’s each()
method or map()
method, is used.
The following codes explain how the value is set and returned using the attr()
method.
The code is tested on the following image:
The following code decreases the image’s width from 300 to 200 pixels. Click on the button labeled Click
to check the effect.
The following code returns the image’s width when the button labeled Click
is clicked.
Free Resources