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

JavaScript

Add & Remove Items from List Using Javascript

Hello,

Over the past week, I have been learning javascript - so if this is a basic question, forgive me. I am trying to create an Add & Remove List. I found some code that will accomplish my objective, and part of that code is displayed below; however, there are a four pieces of the code I do not understand - and one major piece I would like to change. First, what are the $ doing? Second, why is there a colon (:) in front of checked? Third, what is the .is doing? Lastly, why are the + before and after "appID." If you want to see more of the code, you can find it at https://www.pickabundle.com/courses/. For my purposes, I don't need the JQuery or PHP elements - though they are nice touches. I may simply the code a bit by creating "add" and "more info" stationary buttons below my items. The biggest thing I am looking for is the ability to add items from the left to an unordered list on the right that will total up the final cost of the listed items.

<script type="text/javascript"> function bundleRemove(appID) { if($('#check_'+appID+'').is(':checked')) { $('#check_'+appID+'').click(); $('#image_'+appID+'').attr('class', 'icon_normal'); } else { // Do nothing, this app isn't in their bundle. }

Thanks All!

4 Answers

The $ is a jquery identifier.

The :checked is an selector in jquery. It's letting you see if something is checked like a checkbox or a radio button.

The .is is checking state. So it's asking, is that id (#check) checked?

The + sign is a concatenator. It's saying to add check to AppID and add a space.

I think.

Thanks James. So then only the .is and the + are javascript and the rest are aspects of jquery? Is that correct?

.is is jQuery also.

http://api.jquery.com/is/

And the + is javascript which also works in jQuery since jQuery is just a javascript framework.

Thanks for clarifying James! I guess its on to jQuery for me!