This article explains the basics of jQuery attributes.
A previous article explained jQuery Selectors, the most important property of jQuery. This article explains jQuery Attributes. There are many important properties of DOM or HTML elements, like for the <img> tag the src, class, id, title and so on properties. jQuery provides ways to easily manipulate an element's attributes and gives us access to the element so that we can also change its properties. attr() is a method to get the value of an attribute. Let's understand using an example as in the following:Here we will get the value of title for id= divid.So the output will be:Using jQuery attributes we can set the value of other HTML tag elements. Example: Here we are setting the src of the image element.Here the value of src will be replaced by “../images/jquery.jpg”.Similarly we can use addClass(classes) to apply the defined style sheets onto all the matched elements. The output for this code will be:In a similar way I am writing some important methods as in the following. Do practice these and write to me about your experiences.
Do practice these attribute methods and ping me if you have any problem. Keep coding.
Frontend Developer Interview Questions and Answers