Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery display text nested in paragraphs inside a div
    text
    copied!<p>I have HTML that looks something like this:</p> <pre><code>&lt;div class='textbox' data-title='Sometitle'&gt; &lt;div class='textareaedit'&gt; &lt;p&gt;&lt;strong&gt;Test sample text&lt;/strong&gt;&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I'm sometimes going to have a few different <code>&lt;p&gt;</code> tags inside the <code>textareaedit</code> divs, and sometimes <code>strong</code> tags around the text inside the <code>&lt;p&gt;</code> (as in this example), and sometimes a <code>span</code> tag, and sometimes it's going to be without further tags inside the <code>&lt;p&gt;</code>. </p> <p>I want to iterate through each <code>textbox</code> on my page, grab its title and also the text nested inside <code>&lt;p&gt;</code> tags in <code>textareaedit</code>. I'm giving the output via console for testing. This is my jQuery code, but I get no output for the second <code>console.log()</code> line:</p> <pre><code>$('.textbox').each(function() { $this = $(this); console.log($this.attr('data-title')+ ":\n"); $this.children('textareadit').children('p').each(function(){ console.log($(this).html()); // not giving any output, it's blank }); }); </code></pre> <p>I tried <code>$(this).text()</code> as well, but no difference. You may think this example has the sample text inside <code>&lt;strong&gt;</code> tags within the <code>&lt;p&gt;</code>, but I've also tried the same example without the strong, where the text was the direct child of <code>&lt;p&gt;</code>, but it didn't make a difference. How can I capture the text?</p>
 

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