1

The second parameter of jQuery allows you to specify the context in which to search for the selector. For example:

$('.some-selector', '#some-context')

Searches for $('.some-selector') within $('#some-context') - essentially equivalent to $('#some-context').find('.some-selector').

Is there some way to search within a context for a whole block of code containing jQuery selectors, without explicitly setting the context parameter for each one? Some sort of with type of thing?

My scenario is that I have a page with 4 iframes, and I have a bunch of code that contains jQuery selectors, but I want all those selectors to search not only within the main document (default behavior), but also within each of the documents of the 4 iframes. Right now I have a variable $domContext that contains the main document as well as the documents of the 4 iframes, so I can search all 5 documents like this:

$('.some-selector', $domContext)

Which is fine for one line, but I have a bunch of code that this needs to be done for (in fact scattered throughout a ~500 line file). Any better way, or is there no way around it?

jbyrd
  • 5,287
  • 7
  • 52
  • 86

0 Answers0