How to move an element after another element using JS or jquery?

前端 未结 3 492
臣服心动
臣服心动 2020-12-15 17:03

I would like to move one DIV element beside another, it is normally like this:

相关标签:
3条回答
  • 2020-12-15 17:37

    You can use insertAfter to move the element. Docs

    $('.price').each(function() {
        $(this).insertAfter($(this).parent().find('.name'));
    });
    

    Here you have the updated fiddle.

    0 讨论(0)
  • 2020-12-15 17:44

    <div>'s are block-level elements so that's their natural behavior. You could float the div's and then clear them, or use display: inline.

    I think this link would help you understand a bit more though:

    CSS block and inline

    0 讨论(0)
  • 2020-12-15 17:52
    $('.box-related-product-top > div').each(function(){
        $(this).find('.image').appendTo(this);
        $(this).find('.name').appendTo($(this));
        $(this).find('.price').appendTo($(this));
        $(this).find('.cart').appendTo($(this));
    });
    

    Try it: http://jsfiddle.net/m6djm/1/

    0 讨论(0)
提交回复
热议问题