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

was having fun learning html css and javascript....until $jquery().)..{))()(())())(((({}{}

i don't know if its me but the frickin $ sign puts me of and all the ()(()()()(()()()()() and to top it off I've stared at this code for 20 minutes id swear its fine but not working!

var $select = $("<select></select>");

$("#menu").append("$select");

$("#menu a").each(function(){


  var $anchor = $(this);
  var $option = $("<option></option>");

  $option.val($anchor.attr("href"));

  $option.text($anchor.text());

  $select.append($option);

});

thought i read somewhere jquery was easy(er))()())()() think id rather just writing my own javascript

:(

2 Answers

$("#menu").append("$select");

Don't put quotes around $select.

jQuery makes DOM manipulation and traversal extremely simple, but it's still just JavaScript. If you don't like using $, you can replace it with the variable jQuery.

jQuery('#menu').append($select);

Be patient with yourself. Programming is difficult, and it takes time to get right.

Hi Roland,

Sorry to hear your frustrations with jQuery. I understand the growing pains that comes with learning a new language or framework. I've worked with jQuery for over 10 years and I can say that it definitely is a time saver and makes code more readable since so many common functions are consolidated into single functions. Not to mention the fact that it handles some differences and incompatibilities between browsers so we don't have to. It's also community-driven and has years of testing which most code libraries cannot attest for. In other words, its trustworthy and reliable.

It does come up short when you want to create a much larger project that demands a strong, well-thought-out structure. But that's not jQuery's fault. JQuery doesn't actually offer "structure" as part of the package. With that said, if your project has poor structure or no structure at all and you're expecting jQuery to do some magic, then you may find yourself disappointed and frustrated.

In regards to the frequency of the () syntax... that's just code. Most anywhere you go, you will be asked you to make calls to functions. If you're unhappy with the amount of calls to functions then it would be more prudent to re-evaluate your own decisions with your code, rather than the competency of jQuery. If you're unhappy with the fact that by using jQuery you will have to make a lot of calls to functions... then you may need to re-evaluate your priorities.

Stay in the game! It would be difficult to explain to someone that you know javascript but not jQuery, or vice-versa!

Good luck!