Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

New to jQuery. I want to master this language as quickly as I can. So what I'm looking to do is simplify the jQuery (click link below) as much as possible. As well as looking for a great explanation why this is the proper and more efficient way.

Note: This is NOT structured as most tabs you see online. My goal is to filter out each class by clicking each link. The #('.interviewee') are located in just one wrap.

http://jsfiddle.net/efAZU/

share|improve this question
Would it be possible to change the id attribute of the tags to match the class that they're associated with? – Andrew Peacock Jul 6 '12 at 17:28
Yes, I think that's a great idea! – user952851 Jul 6 '12 at 17:30
Please take a look at my solution, it shortens it down a decent amount. – Andrew Peacock Jul 6 '12 at 17:35

migrated from stackoverflow.com Jul 8 '12 at 1:24

2 Answers

up vote 4 down vote accepted

With the the id attribute of the tab changed, you can do something like this: http://jsfiddle.net/Skooljester/efAZU/4/ which shortens it all the clicks into one.

UPDATED FIDDLE

share|improve this answer
1  
+1 for doing it the short way. I was doing the same thing but the opposite(meaning changing the class of the divs and css. – wirey Jul 6 '12 at 17:39
Thank you for this! – user952851 Jul 6 '12 at 17:39
You can remove the if-then logic, if you also make the "all" id "interviewee". That will just turn them all right back on if it's selected. – JerseyMike Jul 6 '12 at 17:42
You get the check... your solution worked. – user952851 Jul 6 '12 at 17:43
I would avoid doing it this way. The abstraction is more limited in scope because now you must have an ID that matches. Plus, why is this "the short way"? mine is 2 lines less ;) – Juventus18 Jul 6 '12 at 17:47
show 2 more comments

I think what you've done is pretty good. I don't think you can "simplify" this any further, but you could abstract it further to use it in other projects. I would probably use the .data() extension method to abstract away the individual blocks for each class:

http://jsfiddle.net/NHx7b/1/

share|improve this answer
That's exactly what I was looking for. The way you wrote the logic and more importantly understand it is what I have achieve in this language. Any advice to learn this language quick? – user952851 Jul 6 '12 at 17:38
1  
I don't remember any particular articles, but Netutts generally has some pretty good stuff. I searched this one out for you - I haven't watched it, but Jeffery Way is pretty good and I mostly agree with his ideas - so this is probably a pretty good starting point: net.tutsplus.com/articles/news/learn-jquery-in-30-days – Juventus18 Jul 6 '12 at 17:44
1  
+1 for teaching me the .data() extension. I've never used that, but I do have a use case for it in my own stuff. – JerseyMike Jul 6 '12 at 17:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.