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 7503337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:11:05+00:00 2026-05-29T21:11:05+00:00

let’s say I have a jQuery UI Slider like so: $(.mySlider).slider({ range: min, min:

  • 0

let’s say I have a jQuery UI Slider like so:

$(".mySlider").slider({
    range: "min", 
    min: 0, 
    max: 10, 
    slide: function(event, ui){
        // do stuff here on slide...
    }
});

Let’s say I have a dynamic input text next to my slider to show the value of my slider like so:

<input id="slider-value" type="text" value="7" style="text-align: center;">

So the full code for my slider is:

<p>
<div id="slider-value" class="mySlider ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all">
<input id="slider-value" type="text" value="7" style="text-align: center;">
</p>

As you can see, initially, when the page loads, my slider has a value of 7. Also, the input text that shows the value of my slider has the same id than my slider div itself. I want the handle of the slider to show that value on page load. If I set the value attribute of the slider equal to 7 like so:

$(".mySlider").slider({
    range: "min", 
    min: 0, 
    max: 10, 
    value: 7, // value of the slider handle
    slide: function(event, ui){
        // do stuff here on slide...
    }
});

This works fine, but obviously, this is not the best way to go because the value of the slider is retrieved from a database and could change (it could be 1, 8, 4, 6, etc…).

Now if I try to do something like:

$(".mySlider").slider({
    range: "min", 
    min: 0, 
    max: 10, 
    value: $(this).closest("p").find("input[id=" + $(this).attr("id") + "]").attr("value"), // setting the value of the slider handle dynamically
    slide: function(event, ui){
        // do stuff here on slide...
    }
});

For some reason, this does not work. The handle does not show the value. What am I doing wrong?, Is it because I cannot use $(this) inside $().slider({}) ?

Please let me know anybody why this isn’t working

Thank you

  • 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-29T21:11:10+00:00Added an answer on May 29, 2026 at 9:11 pm

    What is this here? Don’t think it will point to .mySlider because you are just creating a config and sending it as argument to slider plugin, slider is not yet initialized. Try this.

    var $mySlider = $(".mySlider");
    $mySlider.slider({
        range: "min", 
        min: 0, 
        max: 10, 
        value: $mySlider.next('input').val(),
        slide: function(event, ui){
            // do stuff here on slide...
        }
    });
    

    As a side not ids must be unique of the page. You can use val() method to get the value from input element instead of using attr("value").

    Edited my answer based on your edit(added markup). Used next() method to find the immediate input(sibling) of .mySlider and get the value.

    Update: For multiple sliders use this code

    $(".mySlider").each(function(){
        var $this = $(this);
        $this.slider({
            range: "min", 
            min: 0, 
            max: 10, 
            value: $this.next('input').val(),
            slide: function(event, ui){
                // do stuff here on slide...
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let’s say I have a number like 0x448 . In binary this is 0100
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that I have a set of relations that looks like this: relations
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say i have two tables in db: Car and Part. Car owns arbitrialy
Let's say I have a 12-bit Analog to Digital Converter (4096 bins). And let's
Let's say I have a structure named vertex with a method that adds two

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.