jQuery display text nested in paragraphs inside a div

byrdunmellow

New Member
I have HTML that looks something like this:\[code\]<div class='textbox' data-title='Sometitle'><div class='textareaedit'> <p><strong>Test sample text</strong></p></div></div>\[/code\]I'm sometimes going to have a few different \[code\]<p>\[/code\] tags inside the \[code\]textareaedit\[/code\] divs, and sometimes \[code\]strong\[/code\] tags around the text inside the \[code\]<p>\[/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\]<p>\[/code\]. I want to iterate through each \[code\]textbox\[/code\] on my page, grab its title and also the text nested inside \[code\]<p>\[/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:\[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\]I tried \[code\]$(this).text()\[/code\] as well, but no difference. You may think this example has the sample text inside \[code\]<strong>\[/code\] tags within the \[code\]<p>\[/code\], but I've also tried the same example without the strong, where the text was the direct child of \[code\]<p>\[/code\], but it didn't make a difference. How can I capture the text?
 
Back
Top