Problem: A comma ,separates autonomous selectors. You must first select #fooand then select your internal elements table, tr, td, span, p.
You can use the context attribute:
$("table, tr, td, span, p", "#foo").addClass("Myclass");
or you can link your selectors:
$("#foo").find("table, tr, td, span, p").addClass("Myclass");
source
share