javascript regex to get data between tags code example
Example 1: javascript get content between tags
var str = "<b>Bob</b>, I'm <b>20</b> years old, I like <b>programming</b>.";
var result = str.match(/<b>(.*?)<\/b>/g).map(function(val){
return val.replace(/<\/?b>/g,'');
});
//result -> ["Bob", "20", "programming"]
Example 2: get contents between tags javascript
// Using ES2015+ fat-arrow-function syntax
const getTextOfElement = () => {
const element = document.getElementById('elementId'); // Get desired HTML element
console.log(element.textContent); // Get text of element & display in console
}