In your case, just change the selector and omit find :
var $element = $('#Adiv[name="thename"], #Adiv [name="thename"]');
This will lead to the creation of a jQuery object containing Adiv (if one matches), and any Adiv children that match.
An alternative, more efficient approach if you use jQuery> = 1.4 and know that Adiv definitely exists in the DOM:
$('#Adiv').filter('[name="thename"]').add('[name="thename"]', window.Adiv);
... although I would recommend the first, as it has become cleaner and more sustainable.
Noyo
source share