0

This is kind of a simple question, however, I don't seem to figure out how to do it:

I´ve got a slider filtering some stuff

$("#price").slider(
  {
  range: true,
  step: 5, 
  change: function(e,ui) {
     $('total').filter(function(index) {
      return ( ($("#price").slider("values", 0)) <= $(this).text() <=
                   ($("#price").slider("values", 1)));
     }).parents('div.item').hide();
  }
});

Basically, I want an array with index of each of elements which have been filtered so I can reuse them for other purpose. I was thinking of editing filter function to something like:

$('total').filter(function(index) {
   var matches = ( ($("#price").slider("values", 0)) <= $(this).text() <=
                   ($("#price").slider("values", 1)));
   return matches;
}.myFunction(matches){
//do some stuff here with matched elements 
}

This is not correct, your help is greatly appreciated.

2
  • Which elements do you want? The ones that matched the filter, or the ones that didn't? Commented Apr 11, 2010 at 19:11
  • @Matias - Make sure to accept answers by clicking the check-mark besides the answer that resolved your issue...this helps the next person with the same issue find the answer. Commented Apr 17, 2010 at 11:36

2 Answers 2

1

Update for Comments: You can do this using .map(), like this:

change: function(e,ui) {
  var self = $(this);
  var indexes = [];
  $('.total').filter(function(index) {
      var txt = $(this).text();
      if (self.slider("values", 0) <= txt && txt <= self.slider("values", 1))
      {
        indexes.push(index);
        return true;
      }
  }).parents('div.item').hide();
  //do something with indexes array
}
Sign up to request clarification or add additional context in comments.

8 Comments

Well not exactly,, the filter was working fine (i was just trying to put it simple thus my mistake in the example), the problem is still like to have an array with the numbers I have filtered.
@Matias - You want an array of the values that matched, or didn't match the slider's current range?
@Matias -Updated, give it a shot :)
Thanks Nick for your answer. Unfortunately var=values its returning the text within the divs itself but I just want the position of the elements which have been matched.
@Matias - updated to this...on iPhone though, so untested, hope it works :)
|
0

Here is the full code I am working on:

$("#price").slider(
            {
            range: true,
            step: 5, 
            change: function(e,ui) { 
            $('span.the_total').filter(function(index) {
                    return ( ($("#price").slider("values", 0)) <= $(this).text() <= ($("#price").slider("values", 1)));
            }).parents('div.item_hotel').show();

            $('span.the_total').filter(function(index) {
                     return ( ($("#price").slider("values", 0)) > $(this).text() );
            }).parents('div.item_hotel').hide();

            $('span.the_total').filter(function(index) {
                     return ( ($("#price").slider("values", 1)) < $(this).text());
            }).parents('div.item_hotel').hide();

            }});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.