Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are using <code>.amount</code> as a class every time for your <code>&lt;input /&gt;</code> element. Because classes are usually not unique it takes all <code>&lt;input /&gt;</code> elements with that class and changes its value. So you should indicate that it should look for the span with the <strong>amount</strong> class INSIDE your current container (use the <code>.find()</code> method. (Or you could make use of an <strong>unique id</strong> for each slider.) </p> <p>So if you want to use the same HTML over and over you could simply do:</p> <pre><code>$(document).ready(function() { $(".slider").each(function() { // $this is a reference to .slider in current iteration of each $this = $(this); // find any .slider-range element WITHIN scope of $this $(".slider-range", $this).slider({ range: true, min: 0, max: 100, values: [ 30, 60 ], slide: function( event, ui ) { // find any element with class .amount WITHIN scope of $this $(this).parent().find(".amount").html( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ]); } }); $(".amount").html( "$" + $(".slider-range").slider("values", 0 ) + " - $" + $(".slider-range").slider("values", 1 )); }); }); </code></pre> <p>You should thus also change your HTML and add the span:</p> <pre><code>&lt;div class="slider"&gt; &lt;b&gt;Price range:&lt;/b&gt; &lt;span class="amount"&gt;0&lt;/span&gt; &lt;div class="slider-range"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="slider"&gt; &lt;b&gt;Amount range:&lt;/b&gt; &lt;span class="amount"&gt;0&lt;/span&gt; &lt;div class="slider-range"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>Note that I changed the <code>val()</code> to <code>html()</code> in your JQuery script in order to fill the span content. You can read more about the <code>html()</code> functionality <a href="http://api.jquery.com/html/" rel="nofollow">here</a>.</p> <p>A full working example of this code can be found <a href="http://jsfiddle.net/XZCxt/" rel="nofollow">here on JSFiddle</a>. This should solve your problem!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload