D
D
Dmitry Petrik2016-01-21 16:24:37
JavaScript
Dmitry Petrik, 2016-01-21 16:24:37

Jquery. How to search in already found elements?

I'm making a filter on the Quicksand plugin . And there will be several groups of parameters for searching (subject, class of schoolchildren, level of training, etc.)
I have a container with objects for searching (training courses). I clone the container. All courses. Then I try to find only algebra courses in the entire list of courses.
var $courses = $('#coursesContainer');
var $data = $courses.clone();
$filteredData = $data.find('.course');

$filteredData = $filteredData.end().find(.course[data-subject="Алгебра"]');

Then, in the found algebra courses, I want to find courses only for the 7th grade.
$filteredData = $filteredData.end().find(.course[data-class="7"]');

However search in classes works crookedly. Searches not in already found algebra courses, but in all courses in their entirety. Those. as a result of the search I get all the courses for the 7th grade.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kravchenko, 2016-01-21
@Flexo

maybe you don't need a find, but a filter method?
Why clone, I don't know

var $coursesList = $('#coursesContainer .course');

var $algebraCoursesList = $coursesList.filter('[data-subject="Алгебра"]')
var $algebra7ClassCoursesList = $algebraCoursesList.filter('[data-class="7"]')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question