Get selected element's outer HTML

前端 未结 30 2356
礼貌的吻别
礼貌的吻别 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条回答
  •  执念已碎
    2020-11-21 05:22

    2014 Edit : The question and this reply are from 2010. At the time, no better solution was widely available. Now, many of the other replies are better : Eric Hu's, or Re Capcha's for example.

    This site seems to have a solution for you : jQuery: outerHTML | Yelotofu

    jQuery.fn.outerHTML = function(s) {
        return s
            ? this.before(s).remove()
            : jQuery("

    ").append(this.eq(0).clone()).html(); };

提交回复
热议问题