Get the value of an attribute for the first element in the set of matched elements.
An attribute value may only be a string.
The attributes contains basic information along with some additional information about an HTML element and come in name=value pairs. The attributes gets changed for that html tag using .attr.
The initial states(start states) are represented by attributes. It doesn't give any information about the current state.
Jquery .prop():
Gets the value of a property for the first element in the set of matched elements.
A property can be of any type. For example, the checked property is of Boolean type.
The .prop() method provides a way to explicitly retrieve property values.
In HTML DOM tree,it is the property that works as a representation of an attribute.The corresponding DOM node is created which is an object that contains properties,when the browser parses the HTML code.
Since the prop() stores or keeps the current state value,therefore it is recommended to retrieve the values of the elements that has been modified using JavaScript/jQuery.
Here is an example code for .attr() and .prop() :-
0 Comment(s)