• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JQuery slice() and get()

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was reading JQuery in Action and I read something if you could clarify my doubt:

"Note that this $('*').slice(2,3); is different from $('*').get(2), which returns the third element in the wrapped set, not a wrapped set containing the element."

Does this mean that once the .get() is used you would need to wrap it again in order to use further jQuery. If you have a wrapped set of JQuery DOM objects and you assign them to a var does it act similarly as the get() automagically? I.E. Adding the set as an array of DOM elements to the var and if you needed to further JQuerify it you just need to add it to another wrapped set or wrap it again.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Yule:
Does this mean that once the .get() is used you would need to wrap it again in order to use further jQuery.

Yes. Once you have a reference to an element, you'd need to wrap it again to use any wrapper methods. So use the method that returns whichever you want: an element, or a slice of the wrapped set.

If you have a wrapped set of JQuery DOM objects and you assign them to a var does it act similarly as the get() automagically?

No. Assigning a reference to a wrapped set to a var simply records the reference to the wrapped set just as with any other JavaScript object.
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, thanks.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although, bear in mind that the jQuery wrapper acts a lot like an array, so in some ways, it an be treated like an array of DOM elements.
 
Paul Yule
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
bear in mind



I see what you did there
...
I played around with the lab for a while and I'm fairly comfortable with what gets returned and how to use it now. I want to read it in order (well, I started with the appendix) but I'm sure I'll have more pertinent questions when I get to Event handling, callbacks, Ajax etc...
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very cool. You know where I'll be.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic