How to append anchor tag from one place to another?

This question already has an answer here:

  • How to move an element into another element? 12 answers

  • Or simply

    $('.diagram').append($('.uploadedfiles').removeAttr('class'))
    

    If you have many link to append to diagram div you could use

    $('.uploadedfiles').each(function(){
        $(this).appendTo('.diagram').removeAttr('class')
    })
    

    document.getElementsByClassName("diagram")[0].innerHTML+='<a href="www.google.com">File</a>';
    

    I would recommend you something like this:

    var diagram=document.getElementsByClassName('diagram')[0];
    var uploadedfiles=document.getElementsByClassName('uploadedfiles');
    var l=uploadedfiles.length;
    for(var i=0;i<l;i++){
    diagram.innerHTML+=uploadedfiles[i].outerHTML;
    uploadedfiles[i].parentNode.removeChild(uploadedfiles[i]);
    }
    

    This code deletes every node with class 'uploadedfiles' and adds it into the 'diagram' node.

    Edit: sorry, didn't notice you wanted jQuery code. I rather like the pure js-coding, so I can't help you with jQuery. But I think the other answers are correct. This code can be helpfull for those who don't use jQuery or any other js-library ;)

    链接地址: http://www.djcxy.com/p/42536.html

    上一篇: 根据随机数将div移到某个表格单元格

    下一篇: 如何将锚标签从一个地方附加到另一个地方?