Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

Why can't a person use .add() instead of .append()?

Using .append() works, but I was just wondering why .add() doesn't. It seems to me that they should be equivalent. I don't understand the difference between the two.

Which language are you asking about?

1 Answer

Jason,

In jQuery, add and append do very different things. The add method adds an element or a set of elements to a jQuery object so that you can perform further actions. The append method appends an element or a set of elements to an element in the document itself. Think of the add method as a way of being able to add in other elements to an object and append as a way of appending other elements to the document/page itself.

Here is the article for jQuery's add: https://api.jquery.com/add/

Here is the article for append: http://api.jquery.com/append/