Print out jQuery object as HTML

后端 未结 3 1650
再見小時候
再見小時候 2020-12-29 23:20

Is there a good way of printing out a jQuery object as pure HTML?

ex:





        
3条回答
  •  灰色年华
    2020-12-29 23:46

    If you need to print the object in HTML format, use this extension outerHTML or this outerHTML.

    Update

    Update the link and include the code for second link:

    $.fn.outerHTML = function(){
    
        // IE, Chrome & Safari will comply with the non-standard outerHTML, all others (FF) will have a fall-back for cloning
        return (!this.length) ? this : (this[0].outerHTML || (
          function(el){
              var div = document.createElement('div');
              div.appendChild(el.cloneNode(true));
              var contents = div.innerHTML;
              div = null;
              return contents;
        })(this[0]));
    
    }
    

提交回复
热议问题