Reputation: 3018
I have a string which contains 2 div in it with their text and settings. for example :
<div class="a" id="b">blabla </div><div class="a">Here is the text i need to get </div>
I need to pull out the text from this string, cant use sub string cause the text is dynamic and not always written the same. Thanks
Upvotes: 0
Views: 112
Reputation: 160833
var str = '<div class="a" id="b">blabla </div><div class="a">Here is the text i need to get </div>';
var tmp = document.createElement('div');
tmp.innerHTML = str;
console.log(tmp.innerText || tmp.textContent); // is this what you want?
Upvotes: 3
Reputation: 388326
Try a regex replace like
'<div class="a" id="b">blabla </div><div class="a">Here is the text i need to get </div>'.replace(/(\<div.*?\>|\<\/div\>)/g, '')
Demo: Fiddle
Upvotes: 1