views:

39

answers:

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?

+1  A: 

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.

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