Monday, 15 June 2015

jQuery get image link from string -



jQuery get image link from string -

hey trying png link string houses html in it.

the string looks this:

var thecode = '[caption id="attachment_1794" align="alignleft" width="210"] <a href="http://www.website.com/wp-content/uploads/2012/10/screen-shot-2012-10-30-at- 8.52.48-am.png"><img class="size-medium wp-image-1794" title="difference between , affiliate programs" src="http://www.website.com/wp-content/uploads/2012/10/screen- shot-2012-10-30-at-8.52.48-am-210x300.png" alt="learn , affiliate programs" width="210" height="300" /></a> larn , affiliate programs[/caption]<p><span style="font-size: small;">an article ceo of ad, inc. (ad®), has been published <a title="learn , affiliate programs" href="http://www.mmag.com/articles/85281" target="_blank">m magazine</a>. article titled: "putting right place." </span>';

i have been trying image link via jquery code:

var newstring = $('a[href$=".png"]', thecode).attr('href'); console.log(newstring);

but illustration above returns script5022: syntax error, unrecognized expression:

what missing?

try this:

var thecode = '[caption id="attachment_1794" align="alignleft" width="210"] <a href="http://www.website.com/wp-content/uploads/2012/10/screen-shot-2012-10-30-at-8.52.48-am.png"><img class="size-medium wp-image-1794" title="difference between , affiliate programs" src="http://www.website.com/wp-content/uploads/2012/10/screen-shot-2012-10-30-at-8.52.48-am-210x300.png" alt="learn , affiliate programs" width="210" height="300" /></a> larn , affiliate programs[/caption]<p><span style="font-size: small;">an article ceo of ad, inc. (ad®), has been published <a title="learn , affiliate programs" href="http://www.mmag.com/articles/85281" target="_blank">m magazine</a>. article titled: "putting right place." </span>'; var newstring = $('<div>'+ thecode + '</div>'); console.log($('a[href$=".png"]',newstring).attr('href'));

jsfiddle example

jquery

No comments:

Post a Comment