Getting jQuery-inserted DOM elements without requerying for element after insertion

后端 未结 3 923
北恋
北恋 2021-01-18 09:05

Assuming I insert anything in my DOM with jQuery, like so:

$(\'#someselector\').prepend(\'\');

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 09:24

    You can try something like this:

    $('#someselector')
        .prepend('')
        .find('#someid');
    

    Or if there's only one img:

    $('#someselector')
        .prepend('')
        .find('img');
    

    Alternatively:

    $('').prependTo('#someselector')
    

提交回复
热议问题