Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-07-2012, 04:58 AM   PM User | #1
johnsmith153
New Coder

 
Join Date: Mar 2012
Posts: 81
Thanks: 7
Thanked 0 Times in 0 Posts
johnsmith153 is infamous around these parts
Simple jQuery, changing HTML

I think I'm half way there. I need to change this HTML with jQuery:

Code:
<div class="main-class">
  <div class="div1">
  content 1
  </div>
  <div class="div2">
  content 2
  </div>
</div>

$("div.main-class").each(function() {

  var holder = $(this);

  $("> div", holder).each(function(){

  //here I need to get entire div, including its contents, and place it before the main-class (and remove the old HTML)
  //holder.before() ???

}
Which should leave this:
Code:
<div class="div1">
content 1
</div>
<div class="div2">
content 2
</div>
<div class="main-class">
</div>
johnsmith153 is offline   Reply With Quote
Old 10-07-2012, 03:01 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
this seems to work...
Code:
<script>
$("div.main-class>div").each(function() {
$(this).insertBefore($(this).parent());
});
</script>
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:17 PM.


Advertisement
Log in to turn off these ads.