Reputation: 20538
How can I "clean away" all but the word dog from the html code below using Javascript and perhaps regex? The id will vary.
<div class="tag" id="11">dog</div>
Upvotes: 0
Views: 424
Reputation: 1787
If it's always going to be class=tag
, then a bit of jquery can help with this:
$('.tag').html()
If it's in a string already
var s = '<div class="tag" id="11">dog</div>';
$(s,'.tag').html()
Upvotes: 1
Reputation: 104780
ids should not begin with a digit.
<div class="tag" id="d11">dog</div>
var who= document.getElementById('d11');
alert(who.textContent || who.innerText || '');
Upvotes: 2