Get selected element's outer HTML

前端 未结 30 2509
礼貌的吻别
礼貌的吻别 2020-11-21 04:50

I\'m trying to get the HTML of a selected object with jQuery. I am aware of the .html() function; the issue is that I need the HTML including the selected obje

30条回答
  •  Happy的楠姐
    2020-11-21 05:23

    This is great for changing elements on the dom but does NOT work for ie when passing in a html string into jquery like this:

    $('
    Some content
    ').find('#blog').outerHTML();

    After some manipulation I have created a function which allows the above to work in ie for html strings:

    $.fn.htmlStringOuterHTML = function() {     
        this.parent().find(this).wrap('
    '); return this.parent().html(); };

提交回复
热议问题