Posted in: Using jQuery Core > Frequently Asked Questions

How do I select elements when I already have a DOM element?

If you have a variable containing a DOM element, and want to select elements related to that DOM element, simply wrap it in a jQuery object.

1
2
3
var myDomElement = document.getElementById( "foo" ); // A plain DOM element.
$( myDomElement ).find( "a" ); // Finds all anchors inside the DOM element.

Many people try to concatenate a DOM element or jQuery object with a CSS selector, like so:

1
$( myDomElement + ".bar" ); // This is equivalent to $( "[object HTMLElement].bar" );

Unfortunately, you cannot concatenate strings to objects.