James
James

Reputation: 1

Is it possible to specify that jQuery only searches within a particular div on the page?

In the selector syntax of jQuery $('.string'), is it possible to specify that the search is performed only within a particular div or element on the page?

I ask because I am using a web application framework which has a bug, namely producing container elements with the same id so when I search by id to find the container programmatically, it returns the first container out of the many containers with the same id.

But the container I want always has a unique class attibute. So if I could select that container and tell jQuery to perform it's queries within that container I would have a solution. Is this possible?

Apologies if a basic question.

Upvotes: 0

Views: 47

Answers (3)

Steve Robbins
Steve Robbins

Reputation: 13812

$(".searchInHere").find(".searchForThis")

Upvotes: 2

Guffa
Guffa

Reputation: 700322

You can use the space operator in the selector, i.e. specify that you want to seach for children of the elements with the class:

$('.TheUniqueClass .SomeOtherSelector')...

You can also use an element as scope for the search:

var container = $('.TheUniqueClass');
$('.SomeOtherSelector', container)...

Upvotes: 2

Liam Bailey
Liam Bailey

Reputation: 5905

$(".foo") // select all elements with the class foo

Upvotes: 0

Related Questions