相关疑难解决方法(0)

如何在jquery中替换('something')后获取对象的实际内容

我有这个代码

$(document).ready(function(){
    $('.selector').click(function(){
        obj = $(this);
        obj.replaceWith('<div class="size">whats up man ??!</div>');
        alert(obj.html());
    });
});
Run Code Online (Sandbox Code Playgroud)

我想获得'obj'的新内容,这个内容一直是​​'replaceWith'

但,

我得到旧内容而不是......

我怎样才能得到'obj'的实际内容?

我打算访问新的'obj'

$('.selector').click(function(){
            var obj = $(this),
            repl = $('<div class="size">whats up man ??! <span class="medium"></span></div>');
            obj.replaceWith(repl);
            alert(obj.find('span').attr('class')); //this will print 'undefined'
});
Run Code Online (Sandbox Code Playgroud)

我想要打印'span'的类名称'medium'

jquery this replacewith

11
推荐指数
1
解决办法
2819
查看次数

标签 统计

jquery ×1

replacewith ×1

this ×1