• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jQuery wrapAll()?

 
Mike Anthony
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to insure that all of my fieldsets have a <div> tag enclosing all of the other elements (except the <legend> tag) so I was attempting to use jQuery's wrapall() to do this.

So if I have the following:



then after the wrapAll() is applied I want it to look like the following:



My latest attempt was the following:



However this is not working and I am getting strange results.
It behaves as if it has wrapped all of the elements of all of the fieldsets into one big <div> as opposed to wrapping the elements of each individual fieldset with <div> tags
I have not been able to get the results that I am after.

Can anyone help me out here?

Thank you!
--Michael
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please indent your code? It'd make it easier to see the structure.
 
Mike Anthony
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure I can. Sorry about that, I thought that it auto-indented in my first post and I wasn't paying attention.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This worked for me:

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few ways to do it [doubt you can do it as a 1 liner]



Eric
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric, is there a difference in mine and your 3rd option?
 
Mike Anthony
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all of the help!
I think that I have it working well now. More testing will tell, but it looks good.
I guess that I just need to get this syntax down. It looks like there are so many different ways to accomplish the same thing, I guess this is part of my confusion.
I should probably work through a jQuery tutorial instead of trying to pick this stuff up on the fly...
Thanks again!
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg, I never saw your code. I thought I would run the test and see what happens if you run the selector with 100 of the fieldsets on the page.

Run #E #3E #2E #1Gregg
1185206197214
2188200199206
3186205209209
avg187204202209


A good rule of thumb with JQuery is get as specific as you can with the initial selectors and keep the logic inside the each as minimal as you can.

Eric
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good stuff Eric, thanks.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:Good stuff Eric, thanks.


The good news here is difference of < 1ms with all of the options. [Note tests with FF3.0.10]

Eric

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic