how to get actual content of an object after being replaceWith('something') in jquery

后端 未结 2 718
别跟我提以往
别跟我提以往 2021-01-11 17:44

I have this code

$(document).ready(function(){
    $(\'.selector\').click(function(){
        obj = $(this);
        obj.replaceWith(\'
2条回答
  •  广开言路
    2021-01-11 18:09

    Your updated method is the correct one, just needs a tweak like this:

    $('.selector').click(function(){
      var obj = $(this),
          repl = $('
    whats up man ??!
    '); obj.replaceWith(repl); alert(repl.find('span').attr('class')); });

    You can test it out here. The important change is the repl.find() to look in the new element instead of the old one.

提交回复
热议问题