简体   繁体   中英

Moving html content around the DOM with jquery

I want to load the contents of the gallery element to the stage element by clicking on the gallery element itself. This is noob stuff I'm sure, but I have yet to find an explanation for this. Why doesn't this work?

Also, I am using jquery UI to create a drag and drop interface --> the element inside the #gallery is draggable, and #gallery is droppable

$(document).ready(function () {
    var $galcon = $('#gallery').html();
    $("#gallery").on('click'function () {
        $('#stage').append($galcon);
    });
});

Reference the actual node child and not just the html. In other words, remove the ".html()"

$(document).ready(function () {
    var $galcon = $('#gallery');
    $("#gallery").on('click'function () {
        $('#stage').append($galcon);
    });
});

Try replacing var $galcon = $('#gallery').html() with var $galcon = $('#gallery').text() . Hope this helps!

Are you getting an error in the dev console? Is this the exact code you're running? You need a comma after 'click':

$("#gallery").on('click', function () {
    $('#stage').append($galcon);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM