Mediha
Mediha

Reputation: 760

Set max attribute for the jQueryMobile slider from JavaScript

I have a slider

<div class="slider-container" id="game-mode-slider-container">
                    <label for="game-mode">Game mode</label>
                    <span id="game_mode_indicator" class="slider-indicator">Private</span>
                    <input type="range" name="points" id="game-mode" min="0" value="0">
 </div>

Actually I have couple of them on one page. What I want to do is to set max attr from JavaScript.

$('.ui-shadow-inset.ui-body-inherit.ui-corner-all.ui-slider-input').is('#game-mode').attr('max', '7');
$('.ui-shadow-inset.ui-body-inherit.ui-corner-all.ui-slider-input').is('#game-mode').slider("refresh");

So what I do is I make a selector using class and id both. This doesn't work. If I just use this class it does work, but then I can't have different values for different sliders,because they all have the same class, but different ids. I got this class name using Inspect element in Chrome.

<input type="number" data-type="range" name="points" id="game-mode" min="0" value="0" class="ui-shadow-inset ui-body-inherit ui-corner-all ui-slider-input">

Can someone please help mi with this.

Upvotes: 1

Views: 780

Answers (2)

ezanker
ezanker

Reputation: 24738

With jQuery, set the prop("max") to the new value and then refresh the jQM slider widget:

$("#game-mode").prop("max", selection).slider("refresh");

Here is a DEMO

(click radio buttons to change the max of the slider.)

Upvotes: 3

Red2678
Red2678

Reputation: 3297

Try this:

$('#game-mode').attr('max', '7').slider("refresh");

Upvotes: 0

Related Questions