how to make complex selectors with 'this' jquery
Posted
by Stomped
on Stack Overflow
See other posts from Stack Overflow
or by Stomped
Published on 2010-05-04T11:53:47Z
Indexed on
2010/05/04
11:58 UTC
Read the original article
Hit count: 170
jQuery
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?
© Stack Overflow or respective owner