CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   Simple jQuery, changing HTML (http://www.codingforums.com/showthread.php?t=275548)

johnsmith153 10-07-2012 04:58 AM

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>


xelawho 10-07-2012 03:01 PM

this seems to work...
Code:

<script>
$("div.main-class>div").each(function() {
$(this).insertBefore($(this).parent());
});
</script>



All times are GMT +1. The time now is 02:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.