My task is to perform an adaptive layout, using JS + JQuery to write the entire below-listed unnumbered list into the value of a variable with the goal to place it after the <header> (I will show it with the surrounding tags):
<header> <div class="centering"> <h1> Пример сайта </h1> <ul id="main-menu"> <li><a href="#">ПунктМеню1</a></li> <li><a href="#">ПунктМеню2</a> <ul class="sub-menu"> <li><a href="#">ПунктМеню2-1</a></li> <li><a href="#">ПунктМеню2-2</a></li> </ul> </li> <li><a href="#">ПунктМеню3</a></li> </ul> </div> </header> If you do this with .html("#main-menu") , then only children with respect to <ul> elements will be copied. Then I tried to use .parent :
var MainMenuContents=$("#main-menu").parent().html(); However, together with the list, for some unknown reason, the title is also written into the variable. Can this be avoided? If possible, I ask you not to assign a class or identifier to the tag <header> (and I have several .centering .centering on my page).