Reputation: 155
all
I have a HTML input :<h5><font face="times new roman, times, serif" size="7" style="color: #ff9696; ">Sample</font></h5>
<ul> </ul>
I want to extract everything and pass to javascript variables. For example, font name, size, style color. Can I use RegEx?
I have tried this but no use:
<html>
<script>
var input = '<h5><font face="times new roman, times, serif" size="7" style="color: #ff9696; ">Krishanthan</font></h5> <ul> </ul>';
var div = document.createElement('div');
div.innerHTML = input;
var size = div.getElementsByTagName('size')[0];
var text = size.innerText || size.textContent;
alert(text);
</script>
</html>
Please give me some suggestion...
Thanks.
Upvotes: 0
Views: 1445
Reputation: 112807
You have the right idea, but you are treating size
like an element, whereas actually it is an attribute of the font
element.
var input = '<h5><font face="times new roman, times, serif" size="7" style="color: #ff9696; ">Krishanthan</font></h5> <ul> </ul>';
var div = document.createElement('div');
div.innerHTML = input;
var fontEl = div.getElementsByTagName('font')[0];
var size = fontEl.getAttribute('size');
alert(size);
Upvotes: 3