It is somewhat unclear what you are trying to achieve. However, it looks like you are trying to get the font from an area that is not there. Non-breaking space ( ) is located outside the font tag ( <FONT> . . . </FONT> ) and therefore does not have any of the attributes of this tag (face or size). If you did not parse the space inside the font tag, you could get its face.
Here's a fiddle illustrating this. To see something, I replaced   with Hello .
HTML:
<P><FONT size=5 face="Courier New"></FONT>Hello</P> <p><font size=5 face="Times New Roman">Hello</font><p>
JavaScript:
// Alert the face function handleFonts(e) { alert(this.face); } // Get all the font elements var el = document.querySelectorAll("font"); // Bind event handlers to the elements // The last element of "el" is it length so we only // iterate to el.length - 1 or i < el.length for (var i = 0; i < el.length; i++) { el[i].addEventListener("click", handleFonts, true); el[i].addEventListener("keypress", handleFonts, true); }
Clicking on the text in the tag of the first paragraph does not start anything. Clicking on the text in the second works fine.
We can get around this, though with a little extra javascript.
With HTML, as in the first tag and the next Javascript, we can get the font face inside the tag containing   , although   not in this font tag.
HTML:
<p id="last-p-tag"><font size=5 face="Tahoma"></font>Hello</p>
JavaScript:
// Get the paragraph tag we want var lastPTag = document.getElementById("last-p-tag"); // Bind an event to clicking on it lastPTag.addEventListener("click", function(e) { // Alert the face attribute of the first font element // within that p tag alert(this.querySelector("font").face); }, true);
This is included at the end of the violin.
source share