Is it expected that jQuery $('span').html() turns XHTML br tag to html syntax?

前端 未结 3 980
借酒劲吻你
借酒劲吻你 2020-12-11 05:45

If I have a span tag like this:

 Hi
SecondLine

And I call this jQuery function:

 var ht         


        
相关标签:
3条回答
  • 2020-12-11 06:12

    You aren't actually using XML, so it makes sense that the serialization doesn't use the XML syntax. See also Ian Hickson's essay about sending XHTML as HTML.

    0 讨论(0)
  • 2020-12-11 06:15

    All browsers normalize HTML code while building their DOM tree. So, javascript gains access to already normalized DOM. With all tags properly closed and such.

    0 讨论(0)
  • 2020-12-11 06:34

    It doesn't. It just modifies the browser DOM.

    It is up to the browser to serialise the DOM to HTML or XHTML as it desires when using innerHTML. Different browsers act differently.

    0 讨论(0)
提交回复
热议问题