In jQuery, how can I create a selector for the h1, h2, h3 and p tags inside #con?
Like $('#con h1, #con h2, #con h3, #con p') , but without repeating #con
$('#con h1, #con h2, #con h3, #con p')
#con
You can do any of the following:
$("#con h1, #con h2, #con h3, #con p") // your original $("h1, h2, h3, p", $("#con")) // pass jQuery object in as context $("h1, h2, h3, p", "#con") // pass selector in as context $("#con").find("h1, h2, h3, p") // do what jQuery ultimately does // in the end when passing context // as jQuery or as string selector
I created a nice little jsFiddle that demonstrates all this.
$('h1, h2, h3, ...', $('#con')) will work. This sets the context to be #con and searches for h1, h2, etc. Inside the context (#con).
$('h1, h2, h3, ...', $('#con'))