Reputation: 374
Sample :
<p>
<span class="AM"> ***
<img src="image" title="title" style="vertical-align: middle;">***
</span>
TF1: People needs to learn writting when they are young
</p> .
I
need to extract the image tag fully(not only the resource attribute) from the string.
expected result :
<img src="image" title="title" style="vertical-align: middle;">
Upvotes: 0
Views: 2100
Reputation: 328
Use regular expression to get the image element. the expression will be
/<img[^>]+>/
const match = string.match(/<img[^>]+>/);
const result = match[0];
Upvotes: 0
Reputation: 5875
Select the element, and match the image tag string:
document.getElementsByTagName('p').item(0).innerHTML.match(/(<img[^>]+>)/g);
Upvotes: 0
Reputation: 17004
//Edit: Thought this is a PHP Question.
In PHP you do it so:
$out = null;
preg_match('<img([\w\W]+?)/>', $html, $out);
print_r($out);
Upvotes: 0
Reputation: 82231
You can use:
var ele = $(theHtmlString);
var imgobj= $('.AM img', ele);
Upvotes: 0
Reputation: 318182
Just target the image ?
$('.AM img')
If you need the outer HTML as a string
$('.AM img').get(0).outerHTML
and if all that is a string, pass it to jQuery to parse it
$(string).find('.AM img');
Upvotes: 5