Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere is the mistake? (Can't be specific because I have no clue... :/ )
    primarykey
    data
    text
    <h2>Goal</h2> <p>I was trying to get jQuery to output the class name of the parent container as text in a nested container. To be more specific, I wanted all text in each <code>&lt;p&gt;</code> to be styled with a different font. That's easy enough, I just assigned classes. But I also wanted a <code>&lt;span&gt;</code> in each <code>&lt;p&gt;</code> to show the used font (simply by adding the parents' class name as text). </p> <h2>Examples/Tests</h2> <p><a href="http://www.cgeese.de/tests/webfonts/index.html" rel="nofollow">THIS link shows the not-working page</a></p> <p>Weirdly enough, </p> <p><a href="http://jsfiddle.net/qrFMY/4/" rel="nofollow">THIS jsfiddle test (kinda*) works</a></p> <h2>(a bit of the) Code</h2> <p>The second link is also very convenient when checking the code, so I hope it's ok if I only paste the jquery-stuff in here (I find it very likely that I messed that part up... again...)</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { $("span").each(function() { var usedfont= $(this).parent().attr("class"); $(this).text(usedfont); }); }); &lt;/script&gt; </code></pre> <h2>My train of thoughs:</h2> <ol> <li>when dom is loaded, </li> <li>iterate through all span-elements,</li> <li>setting a variable as the class name of the parents' element and</li> <li>setting the text of the span-element as this variable.(ergo echoing out the parents' class name).</li> </ol> <h2>Question(s)</h2> <p>Why won't the page behind the first link work? And why does the jsfiddle test deliver?</p> <p><strong>*</strong> Why does the jsfiddle-result start out with <code>});//]]&gt;</code>? </p> <p><strong>Thanks a bunch!</strong></p>
    singulars
    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.
 

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