More jQuery and RWD

Since the 301 course here at Code Fellows covers a lot of jQuery, I get the feeling I will be writing about it quite a bit. That’s ok though given that writing is suppose to help me learn it better.

To remain true to my first post, I am trying to follow these three questions when writing a post:

  1. What is one interesting piece of code I have learned since the last post and why?
  2. What do I feel I have improved upon since the last post?
  3. What is one thing I want to learn more about before the next post?

So I think the most interesting piece of code I’ve come across this last week is probably the ‘attr’ method in jQuery:

$('#specificSection div').attr();

The fascinating use we were taught this week was actually attaching an attribute to the element, then later referencing that element by the attribute you attach. For example:

$('#specificSection div').attr('data-category', 'some value');

This will select the div within a ‘specificSection’ element (assuming it’s the only div, or it will give you an array). This gives the element an attribute it didn’t previously have:

<div data-category="some value"></div>

Then later you can access this element programmatically with the use of that attribute:

$('div[data-category="some value"]');

You might be wondering “why don’t you just give it an ID and access it that way?”. Good question! They way I understand it, the value is in the separation of concerns. You wont step on anyone’s feet if they happen to be using the same id value in your project, and you wont mix up any styling you may have attached to a certain ID. This method gives you a programatic way to set key value pairs to an element that is used only by your javascript/jquery code and doesn’t mess with the styling or markup of the page.


2. What have I improved upon since the last post?

Well I have definitely improved on my understanding of css selectors and jQuery specific selectors. I also feel I have improved on my understanding of clean code and writing code with clear notes.

3. Something I want to learn more about:

Definitely want to learn more about working on a team. We have been pair programming in this class but sometimes its impossible to explain something to someone that doesn’t understand the basics of their own computer. Quite frustrating, even as I am told that I am one of the most patient people, it’s really frustrating.