views:

23

answers:

2

I have a table that displays rows based on a drop down list option. The rows are dynamically created. I use the value on the ddl for the initial row, then a simple counter to make it unique. Is there a way to say something like show all the rows that start with "tableShoes" even though the rows are something like tableShoes1, tableShoes2, etc?

$('#itemSelect').change(function() {
    var item = $('#itemSelect').val();
    $('#itemList tr').each(function() {
        $(this).hide();
    });
    $('#' + item + 'Header').show();         
    $('#' + item + '1').show();
    //Because the table is dynamic, I am not sure how many 
    //rows would be available so I only see the first option.
});
+1  A: 

I would suggest adding the same CSS class name to each row as it is added, perhaps the same as the value of the selected item. That way your last line could just be:

$('.' + item).show();

And you wouldn't have to worry about the index.

Mike McCaughan
that attribute works great... thanks!
A: 

this selector shoud solve your problem: $('[id|=tableShoes]')

Francesco Abbruzzese