Dextranovich
Dextranovich

Reputation: 55

Get content from specific tag with its class name from html string

I have a little problem. With GET method I am getting data as an HTML String. And now, I want to display only data from:

CONTENT

How I can filter only this tag and class from the html string that is returned with GET method?

Thank you.

Upvotes: 2

Views: 3873

Answers (1)

vibhor1997a
vibhor1997a

Reputation: 2376

What you can do is to create a DOM element and set the innerHTML property to the HTML string.

let res = '<div class="wiki-holder prepend-top-default append-bottom-default">CONTENT</div>';//In your case this will contain the whole HTML string

let div = document.createElement('div');
div.innerHTML = res;
let selected = div.getElementsByClassName('wiki-holder prepend-top-default append-bottom-default');

document.write(selected[0].innerHTML);//The first element of this className

Upvotes: 2

Related Questions