2
<span id='a'><img src='b.gif' /></span>
<script>
alert(document.getElementById('a').innerHTML);
</script>


The output is: <img src="b.gif" />

'b.gif' is being shown as "b.gif"

Viewing the source code in FireBug also shows double quotes. Why is this happening?

gom
  • 796
  • 2
  • 9
  • 23
  • 1
    Firebug renders the DOM structure itself. Probably they always use double quotes. Just check the generated HTML code (right click > view source). – Styxxy Jul 18 '12 at 19:11

1 Answers1

2

Double quotes are the standard for attributes, single quote are obviously acceptable though.

The innerHTML is the processed set of tags, so the browsers will set the attributes with double quotes as standard

As has been pointed out, there is no "standard" when it comes to double or single quotes on attributes.

My guess would be that browsers use double quotes by default, and therefore when you request the innerHTML, it will format them as such. If I am incorrect, I will remove this answer immediately

freefaller
  • 19,368
  • 7
  • 57
  • 87
  • I am not the downvoter, but @freefaller about what [standard](http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2) are you talking about? single quotes are as much acceptable, as double quotes. – Engineer Jul 18 '12 at 19:16
  • 2
    I didn't downvote, however there is absolutely no difference between double and single quotes, i.e. "double quotes are the standard" is wrong. ( http://stackoverflow.com/questions/2373074/single-vs-double-quotes-vs ) – fresskoma Jul 18 '12 at 19:16
  • @Engineer, I guess you're right... maybe its just the default for browsers then. Will edit – freefaller Jul 18 '12 at 19:19
  • I observed this both in Firefox and Chrome. – gom Jul 18 '12 at 19:20