• L...">
    Geek Answers Handbook

    Jquery: duplicate and paste html

    hmm ok heres abbreviated code

     <div id="SideCategoryList">
            <div class="BlockContent">
               <ul>
                  <li><a href="#">Link A</a></li>
                  <li><a href="#">Link B</a></li>
              </ul>
           </div>
         </div>
        <div id="navcont">
        <ul class="menu" id="menu">
          <li id="hov"><a href="#">Top Link</a></li>
          <li><a href="#">Bottom Link</a></li>
        </ul>
       </div>
    

    I want to use jquery to duplicate Whats in the first ul to the first li in #menu so that it looks like this:

    <div id="SideCategoryList">
            <div class="BlockContent">
               <ul>
                  <li><a href="#">Link A</a></li>
                  <li><a href="#">Link B</a></li>
              </ul>
           </div>
         </div>
        <div id="navcont">
          <ul class="menu" id="menu">
             <li id="hov"><a href="#">Top Link</a>
                <ul>
                   <li><a href="#">Link A</a></li>
                   <li><a href="#">Link B</a></li>
                </ul>
            </li>
            <li><a href="#">Bottom Link</a></li>
          </ul>
       </div>
    

    so the finished product will be a 2-level list ... let me know if this is makin sense lol

    +5
    jquery
    Alex Dec 14 '10 at 22:29
    source share
    3 answers
    $("#hov").append($(".BlockContent ul").clone());
    
    +3
    Emmett Dec 14 '10 at 22:48
    source share
    var content = $('#BlockContent').html();
    
    $('#hov').append(content);
    

    will add contentat the end of everything innerhtml $('#hov').

    those. after <a href="#">Top Link</a>.

    hope that helps :)

    +1
    Damien-wright Dec 14 '10 at 22:49
    source share

    maybe something like this ...

    var copied_html = $('#BlockContent').html();
    copied_html.insertAfter($('#menu li#hov a'));
    
    0
    jordanstephens Dec 14 '10 at 22:32
    source share

    More articles:

    • Scrolling down a page - jquery
    • Idiomatic python: distribution or smoothing? - python
    • Communication with clang-llvm - c ++
    • The best way to add SNMP support to your own Debian application is c ++
    • ImageMagick: convert image to black and white, with high contrast! - imagemagick
    • Animated image does not move when javascript method is called for a long time - javascript
    • Когда вам нужно беспокоиться о безопасности потоков? - java
    • How to convert native path (NT) to Win32 path name? - c ++
    • How to get the name associated with an open pen - c
    • CSS: specific fluid layout issues - html

    All Articles

    Geek Answers | 2019