Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6119851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:36:04+00:00 2026-05-23T15:36:04+00:00

I have multiple sliders on a page each with class slider and each is

  • 0

I have multiple sliders on a page each with class “slider” and each is prefixed with a checkbox. When the page is loaded, the checkboxes are populated via PHP as either checked or unchecked. Based on this, I would like to enable or disable the sliders.

Removing the irrelevant parts, I have:

$(".slider").slider({
        ...
        disabled: function()
        {
            var $field = $(this).prevAll("input");
            return $field.is(':checked');
        },
        ...
});

I am not even sure if it is possible to pass an anonymous function to the disabled option. Is this legit? It doesn’t seem to be working…

Of course I could initialize #slider1, #slider2, #slider3…etc seperately, but I’m looking for the most elegant and compact solution.

Is it that $(this) has gone out of scope now that it’s inside of the option? How does javascript work in these cases? Provided it hasn’t… I know the $(this).prevAll(“input”) selector is accurate as I’ve checked it with Firebug.

Thoughts? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:36:04+00:00Added an answer on May 23, 2026 at 3:36 pm

    am not even sure if it is possible to
    pass an anonymous function to the
    disabled option. Is this legit?

    Nope. You can’t pass a function reference as an argument to that option.

    You could immediately execute that anonymous function, but the value of this would be wrong:

    $(".slider").slider({
            ...
            disabled: (function()
            {
                var $field = $(this).prevAll("input");
                return $field.is(':checked');
            })(),
            ...
    });
    

    As a workaround, you could wrap your code in an .each() block:

    $(".slider").each(function () {
        var $this = $(this);
        var disabled = $this.prevAll("input").is(":checked");
        $(this).slider({
            ...
            disabled: disabled
            ...
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that has multiple sliders (from http://www.switchonthecode.com/tutorials/using-jquery-slider-to-scroll-a-div ) and since each
I have multiple classes that all derive from a base class, now some of
I have multiple branches of a project checked out, each under their own directory
I would like to insert multible sliders in one page. I have a block
I have multiple table rows that has a set of radio buttons on each
I am using multiple jquery cycle sliders on a single page that i am
I have this web page I'm developing that displays multiple images of one product
Suppose I have a page called view.php, if I give an argument like view.php?q=fruit,
I am trying to make a Content Slider for my site. I have multiple
I have a multiple jQuery slider and write custom style for that , in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.