Believe it or not, this isn't incredibly bad.

One thing you should do is search for things by ID using the ID only. 
It's actually a bit faster.  If you want to remind yourself of the tag
type, put in a comment after the line.

Another thing you can do to make this a bit cleaner is to use a comma to
put things that you're doing the same thing(s) to in the same search.

e.g.
$('#standard dd,#profi dd').removeClass('ausgewaelt');

Keep in mind also that you can get to the DOM element in an event callback
through its data object reference.  This way, you don't have to re-search
for li#normal from within the click event function that you glued to it. 
Just remember to name the reference.  I'm not sure how useful it is in
this particular case, but it's helpful to know.

HTH,
- Brian


> Hello,
>
> I am looking for a way to simplify this chunk of code:
>
>
>         $('li#normal').click(function() {
>             $('#bereit').ScrollTo(800);
>             $('li#normal dd').toggleClass('ausgewaehlt');
>             $('li#standard dd').removeClass('ausgewaehlt');
>             $('li#profi dd').removeClass('ausgewaehlt');
>
>             $('label#label_radiobutton_1').toggleClass('ausgewaehlt');
>             $('label#label_radiobutton_2').removeClass('ausgewaehlt');
>             $('label#label_radiobutton_3').removeClass('ausgewaehlt');
>
>             $('input#radiobutton_1').attr('checked','checked');
>             $('input#radiobutton_2').attr('checked','');
>             $('input#radiobutton_3').attr('checked','');
>         });
>         $('li#standard').click(function() {
>             $('#bereit').ScrollTo(800);
>             $('li#normal dd').removeClass('ausgewaehlt');
>             $('li#standard dd').toggleClass('ausgewaehlt');
>             $('li#profi dd').removeClass('ausgewaehlt');
>
>             $('label#label_radiobutton_1').removeClass('ausgewaehlt');
>             $('label#label_radiobutton_2').toggleClass('ausgewaehlt');
>             $('label#label_radiobutton_3').removeClass('ausgewaehlt');
>
>             $('input#radiobutton_1').attr('checked','');
>             $('input#radiobutton_2').attr('checked','checked');
>             $('input#radiobutton_3').attr('checked','');
>         });
>         $('li#profi').click(function() {
>             $('#bereit').ScrollTo(800);
>             $('li#normal dd').removeClass('ausgewaehlt');
>             $('li#standard dd').removeClass('ausgewaehlt');
>             $('li#profi dd').toggleClass('ausgewaehlt');
>
>             $('label#label_radiobutton_1').removeClass('ausgewaehlt');
>             $('label#label_radiobutton_2').removeClass('ausgewaehlt');
>             $('label#label_radiobutton_3').toggleClass('ausgewaehlt');
>
>             $('input#radiobutton_1').attr('checked','');
>             $('input#radiobutton_2').attr('checked','');
>             $('input#radiobutton_3').attr('checked','checked');
>         });
>
>
> It controls a list, when you click on one of the three items, it scrolls
> down to a online form (first line), the item is highlighted (first three
> lines), one of three radioboxes is checked (line 6-8) and the label for
> the
> checked radiobox is also highlighted (last three lines).
>
>
> Can you help me?
>
> Thanks,
> Dominik
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to