More elegant code

More elegant code


Hi,
I've just wrote this piece of code.
It works but i think it could be written better.
I will explain a little bit the code:
clicking a on <a> child of the <ul> in the <div> with id
"precollection" will remove from all the link the class sel and then
reassign it only to clicked link.
Then I need another loop with the each function because i want to
have a numeric identifier of the link i clicked.
$(document).ready(function() {
$('#pre-collection ul a').click(function(){
    $('#pre-collection ul a').removeClass('sel');
    $(this).addClass('sel');
    $('#pre-collection ul a').each(function(index){
     if($(this).attr('class') == 'sel'){
        num = index;
     }
    });
    $('#pre-collection #description').html(num);
    return false;
});
});
Some suggestion for a lightweight code?