What is a difference between attr and prop in jQuery

Forums jQueryWhat is a difference between attr and prop in jQuery
Staff asked 2 years ago

What is the difference between attr and prop in the jQuery

Answers (1)

Add Answer
Staff answered 2 years ago

prop – 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.

Subscribe

Select Categories