homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Add class to multiple same items
add class to jquery ui slider handles

5+ Year Member

Msg#: 4275470 posted 8:18 pm on Mar 2, 2011 (gmt 0)

I'm using this bit of javascript to add a class to the left and right handles of the jQuery UI Slider

$(document).ready(function() {
handle = $('.slider A.ui-slider-handle');

it's working if I only have one slider on the page but it doesn't seem to want to add the class to multiple items that exist in the same div class. My HTML code is

<div class="slider">
<label for="amount">Price range:</label>
<input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" />
<div class="slider-range"></div>
<div class="slider">
<label for="amount2">Price range:</label>
<input type="text" id="amount2" style="border:0; color:#f6931f; font-weight:bold;"/>
<div class="slider-range2"></div>

Been trying to figure this out for a few hours now so I thought I'd ask to see if anyone can point me in the right direction. Thanks in advance.



WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

Msg#: 4275470 posted 8:54 pm on Mar 2, 2011 (gmt 0)

Does this work?

$(document).ready(function() {
$('.slider A.ui-slider-handle').each(function(idx) {
$(this).addClass(idx % 2 == 0? 'left-handle': 'right-handle');


5+ Year Member

Msg#: 4275470 posted 9:02 pm on Mar 2, 2011 (gmt 0)

Thank you so much - you've twice in the space of two days been fantastic at providing a solution to my problem. I really do appreciate this. Thanks Fotiman

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved