Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS jQuery Basics (2014) Creating a Mobile Drop Down Menu Perform: Part 3

Kartik Kapoor
Kartik Kapoor
3,016 Points

What is the difference between attr() and prop()?

8

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Kartik,

The attr method works directly with the DOM (document object model), whenever you use this method and have the developer tools open you will notice that the attribute of the element changes which is because this method uses the setAttribute method on the DOM element.

The prop method is slightly different as it doesn't update the attributes on the DOM element directly, instead it updates the properties on the DOM object therefore you won't see a visual change even though the value does change, the values you can pass to prop are the same as attr but it's recommend you use prop as it uses newer DOM API's and has far better compatibility with IE9+.