What is a difference between attr and prop in jQuery
Answers (1)
Add Answerprop – This method returns the current value.
attr – This method returns the default value.
prop – When a user wishes to modify the value of an HTML tag’s attribute, they typically utilise this approach.
attr – The primary application of this method is to specify the attribute’s default value for an HTML tag.
prop – It modifies the HTML tag’s properties in accordance with the DOM tree.
attr – It modifies the HTML tag’s attributes.
prop – syntax:- $(selector).prop(property)
attr – syntax:- $(selector).attr(attribute)
prop – There are three requirements. Value, a property, and a function.
attr – Three parameters are required: an attribute, a value, and a function.