Jquery – selector, made of object and string, can it be done

concatenationcss-selectorsjqueryobjectstring

Assume that there is an object, passed as an argument to a function. the argument name is "obj".
can it be concatenated as followed?

$(obj + " .className")......

OR

$(obj + "[name='obj_name'])......

Thanks.

Best Answer

No, but you can use the filter() method to filter out the object itself:

$(obj).filter('.className')...
$(obj).filter('[name=obj_name]')...

Or, if you want to find the children with those qualities:

$(obj).find('.className')...
$(obj).find('[name=obj_name]')...

Or, an alternative syntax to find, giving the obj as the context to the $() function:

$('.className', obj)...
$('[name=obj_name]', obj)...