1

I am trying to read the value of my slider from a DIV element's title (which may be the issue). That is pushed into the following:

$(document).ready(function() {
    $(".myslider5").slider({
        min: -1000,
        max: 1000,
        value: parseInt($(this).attr("title")),
        slide: function(event, ui) {
              // more actions
        }
    });

I think I get NaN error. Any clues?

6
  • how are the div's titles like? Commented May 4, 2010 at 0:20
  • <div class="myslider5" id="id-1" title="-791">-791</div> Commented May 4, 2010 at 0:26
  • @publicRavi - Are you setting the min/max? the default range is 0-100, which -791 wouldn't fall in. Commented May 4, 2010 at 0:37
  • @Nick C Yes, I am. Just wanted to show the important lines :) Commented May 4, 2010 at 1:01
  • @publicRavi - Is there more than one .myslider5? Commented May 4, 2010 at 1:08

2 Answers 2

2

If there's more than one of this class, you'll need to iterate over them and create the sliders using .each(), like this:

$(".myslider5").each(function() {
    $(this).slider({
        value: parseInt($(this).attr("title")),
        slide: function(event, ui) {
              // more actions
        },
        min: -1000,
        max: 1000
    });
});

Here's an example of the above, otherwise you'll get the value from the title of the first of these in the set, you can see the .attr() documentation or details:

Get the value of an attribute for the first element in the set of matched elements.

Sign up to request clarification or add additional context in comments.

1 Comment

@Nick C I had tried that, but held on to the $(".myslider5").slider({. Thank you :)
0

It is possible that $(this) is not taking exact value so try to give value as:

$(".myslider5").each(function() {
    $(this).slider({
        value: parseInt($(".DiVID").attr("title")),
        slide: function(event, ui) {
              // ...
              // more actions
              // ...
        },
        min: -1000,
        max: 1000
    });
});

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.