Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's somewhat unclear what you're trying to achieve. However it looks like you are trying to get the font face from an area that has none. The non breaking space (<code>&amp;nbsp;</code>) is outside the font tag (<code>&lt;FONT&gt; . . . &lt;/FONT&gt;</code>) and therefore has none of the attributes of that tag (face or size). If the non breaking space were inside the font tag, you could get its face.</p> <p>Here's a <a href="http://jsfiddle.net/Ess9V/1/" rel="nofollow">fiddle</a> illustrating that. For the sake of seeing something, I replaced <code>&amp;nbsp</code> with <code>Hello</code>.</p> <p>HTML:</p> <pre><code>&lt;!-- Hello is outside the font tag. --&gt; &lt;P&gt;&lt;FONT size=5 face="Courier New"&gt;&lt;/FONT&gt;Hello&lt;/P&gt; &lt;!-- Hello is inside the font tag. --&gt; &lt;p&gt;&lt;font size=5 face="Times New Roman"&gt;Hello&lt;/font&gt;&lt;p&gt; </code></pre> <p>Javascript:</p> <pre><code>// 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's length so we only // iterate to el.length - 1 or i &lt; el.length for (var i = 0; i &lt; el.length; i++) { el[i].addEventListener("click", handleFonts, true); el[i].addEventListener("keypress", handleFonts, true); } </code></pre> <p>Clicking on the text in the first paragraph tag triggers nothing. Clicking on the text in the second works fine.</p> <p>We can get around this though with a little extra javascript.</p> <p>With HTML like in the first tag and the following Javascript, we can get the face of the font within the tag containing <code>&amp;nbsp</code>, even though <code>&amp;nbsp</code> is not within that font tag.</p> <p>HTML:</p> <pre><code>&lt;p id="last-p-tag"&gt;&lt;font size=5 face="Tahoma"&gt;&lt;/font&gt;Hello&lt;/p&gt; </code></pre> <p>Javascript:</p> <pre><code>// 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); </code></pre> <p>This is included at the end of the fiddle.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload