Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts

    How all elements with id above a number

    I'm using a jQuery slider and I have a nubmer of elements with ID's like id1, id2, id3 etc.

    when the slider value (set to increments of 1) is e.g 4 I need it to show elements id1,id2,id3,id4 and leave the rest hidden.

    How would I go about doing this?

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 565 Times in 558 Posts
    As soon as you feel "forced" to assign id attributes like this to your elements, you should start using class attributes instead and then use jQuery functionality to select subsets of this class
    Code:
    var sliderValue = $('#yourslider').val();
    $('.yourclass:lt(' + sliderValue + ')').show();
    $('.yourclass:gt(' + (sliderValue-1) + ')').hide();

  • Users who have thanked devnull69 for this post:

    tomharto (04-23-2013)

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    824
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Okay, I'll change it to class, thanks.

    I guess the :lt :gt are less than/greater than?

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 565 Times in 558 Posts
    Exactly


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •