user1734190
user1734190

Reputation: 167

get text using jQuery

I want to get text and image separately from the below paragraph in jQuery.

<item>
    <title>Brazil 2014: Same old story, different ending</title>
    <category>England</category>
    <category>Euro 2012</category>
    <category>Germany</category>  
    <category>Italy</category>   
    <category>Mario Balotelli</category>
    <category>North End Galactico</category>
    <category>Roy Hodgson</category>   
    <category>Spain</category>
    <dc:creator>Tony Davies</dc:creator>
    <pubDate>Fri, 30 Nov 2012 09:00:48 +0000</pubDate>
    <link>http: 
  //www.footballfriendsonline.com/blogs/2012/11/30/brazil-2014-same-old-story-different- 
  ending.html</link>
    <guid isPermaLink="false">565562:8695411:31453180</guid>
    <description>
        <![CDATA[
            <p>
                <span class="full-image-float-left ssNonEditable">
                    <span>
                        <img src="http://www.footballfriendsonline.com/storage/pictures/premiership/wba/hODGSON.JPG?__SQUARESPACE_CACHEVERSION=1354201352468" alt="" />
                    </span>
                </span>
            </p>
            <p>This summer saw England head to Euro 2012 carrying the hopes of a nation that expected little from their team.</p>
        ]]>
    </description>
    <wfw:commentRss>http://www.footballfriendsonline.com/blogs/rss-comments-entry- 
 31453180.xml</wfw:commentRss></item>

I'm using this it is showing blank value.

var container = $(this).find('description').text();
var ctext=$('p',container).text();
var container=container.substr(0,300).replace(/\s+?(\S+)?$/g, '')+suffix;

It is this container showing both the image and text. I want to get the text i.e in a <p> tag.

Upvotes: 2

Views: 122

Answers (1)

YardenST
YardenST

Reputation: 5257

The container should be jQuery element/selector, not a text. Try this:

var ctext=$('p',"description").text();

working link http://codepen.io/yardenst/pen/pEtiA

Upvotes: 2

Related Questions