how to make complex selectors with 'this' jquery
- by Stomped
I have an event handler that needs to do something to one of its children, based on some saved data. So what I'm currently doing is something like this:
// Get the ID of 'this'
item_id = $(this).attr('id');
// building a selector like $('#item1 .child_3')
$('#' + item_id + ' .child_' + spVal).addClass('blah');
But this seems a little cumbersome. I've tried:
$(this + ' .child_' + spVal).addClass('blah');
and it doesn't work, which doesn't really surprise me. Is there a better way to do this then the successful way I've outlined above?