Preserving single or double quotes around attributes in browser

后端 未结 2 1946
天命终不由人
天命终不由人 2021-01-26 08:40

I want to preserve single or double quotes around html attributes, specifically for innerHTML within the content editable div. I know this is weird requirement, but I am looking

2条回答
  •  温柔的废话
    2021-01-26 09:14

    Those quotation marks aren't actually in the DOM at all; the DOM is a data structure, with string objects for the attribute values. It doesn't retain any information about whether the strings were single- or double-quoted in the original source, since there's no difference in meaning between the two forms.

    The HTML that you see in Firefox's developer tools is not a copy of your HTML source code; it's generated from the DOM data structure. And since the DOM doesn't include any information about how the strings were quoted in the original source code, the developer tools just quotes them all in a default way when generating new HTML from the DOM.

提交回复
热议问题