2011-06-01 55 views

回答

19

你可以做任何以下的:

$("#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've created a nice little jsFiddle that demos all of this.

+0

非常感謝你斯科特!非常有用 – Victor 2011-06-01 23:48:54

+0

完全沒問題! = d – 2011-06-02 01:45:32

5

$('h1, h2, h3, ...', $('#con'))會工作。這將上下文設置爲#con並在上下文(#con)內搜索h1,h2等。