3

I have a div structure like this

<body>
  <div>
    <nav></nav>
    <nav></nav>
    <div>
      <div id=parent-conatiner>
        <div>
          <ul>
            <li></li>
            <li></li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</body>

now i want to remove all the parent element of the div #parent-container but not removing any element inside the #parent-container div, i dont want to use clone and then include the element in the body because i use some kendo controls inside the #parent-container and the kendo controls stopped working when i use the cloned div basically i dont want to use the following logic

var $cloned=$('#parent-conatiner')
$('body').empty();
$('body').append($cloned);

any help would be appreciated, thank you

Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85

2 Answers2

5

Use the below method, all event bindings are kept intact.

$('#parent-conatiner').parentsUntil('body').replaceWith($('#parent-conatiner'));
Shintu Joseph
  • 962
  • 7
  • 19
0

Use the jquery unwrap() function

or use the cloning method and eventdelegate you kendo controls

another solution will be:

$('body').append($('#parent-conatiner'));
$('body div:last').prevAll().remove();

but this should be the same problem like the cloning

another option is detach()

var el = $('#parent-conatiner').detach();
$('body').empty().append(el);
madalinivascu
  • 32,064
  • 4
  • 39
  • 55