Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jQuery - unable to obtain slider values from wrapped set of sliders

 
Joe Lemmer
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I have some jQuery sliders on a web page and I want to get their values and store those values in an Array.

I didn't think this would be a problem as I having been getting the slider values no problem when I have been accessing them as follows:



So I thought the best way to get all the values would be to get a wrapped set of all the sliders and then iterate through this and get all the values as follows:



but it's not working. I've used alerts to debug, and it's the code in the for loop that is the problem. As far as I can see, this code is getting a wrapped set of divs with class 'slider', getting the one at the index of 'i', getting the value of the slider and assigning it to the correct element of the array.

I have used $('div.slider').size() to see that the wrapped set had elements to it and it did, so I am very confused and wonder if anybody can point me in the right direction.

Thank you in advance.

Joe
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're kinda doing it inside out.

Rather than apply the loop from the "outside", investigate the use of jQuery's .each() method.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(and even more relevant to your situation, jQuery's .map() method).
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
get() does not return a jQuery object, it returns the DOM Object

secondly you are getting the value wrong.

http://docs.jquery.com/UI/Slider#methods

Eric

 
Joe Lemmer
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear and Eric,

Thank you. I found both your replies very helpful and have fixed my problem as a result. I have now have the following (I think) pretty nice code:



Sweet!

Thanks again

Joe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic