最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Chrome console format html - Stack Overflow

programmeradmin4浏览0评论

Is it possible to make Google Chrome console to format output html. So if I will

console.log('<ul><li>1</li><li>2</li></ul>'); 

It will show real list instad of html markup

Is it possible to make Google Chrome console to format output html. So if I will

console.log('<ul><li>1</li><li>2</li></ul>'); 

It will show real list instad of html markup

Share Improve this question edited Feb 25, 2015 at 8:16 Adam Pietrasiak asked Jul 22, 2013 at 9:54 Adam PietrasiakAdam Pietrasiak 13.2k10 gold badges81 silver badges96 bronze badges 2
  • Note: Dont use console in live. – Grim Commented Jul 22, 2013 at 10:21
  • Know it, Its debugging purpose. – Adam Pietrasiak Commented Jul 22, 2013 at 14:28
Add a ment  | 

3 Answers 3

Reset to default 5

No, it does not seem possible. The Console API reference for Google Chrome mentions no such thing.

You can however create a debug div tag and add your contents to that:

<div id='debug'></div>

and

document.getElementById('debug').innerHTML = '<ul><li>1</li><li>2</li></ul>';

A simple hack might be something like this:

console.html = function(data){
   var self = this;
   for(var i=0; i< arguments.length;i++){
      var wrapper= document.createElement('wrapper');
      wrapper.innerHTML = arguments[i];
      self.log(wrapper)
   }
}

Yes,

you can show a list using

console.log("hi",[1,2,3,4],"ho");

(The , are important, + will convert the array into String.

No, plain html is not possible.

发布评论

评论列表(0)

  1. 暂无评论