Is there a way to use javascript to count all the letter "d" in a specific table? I have a table of information on my page and I need some way of counting specific letters in the information.
So the out put would be something like d=2
| SitePoint Sponsor |
Is there a way to use javascript to count all the letter "d" in a specific table? I have a table of information on my page and I need some way of counting specific letters in the information.
So the out put would be something like d=2


Code:<script type="text/javascript"> function find(){ var el = document.getElementById('tableid'); el = el.getElementsByTagName('td'); var td, i = 0, str =""; while(td = el[i++]) { str += td.innerHTML; } alert(str); var c = "d"; var n = str.match(RegExp('('+c+')','g')).length; alert(n); // 6 } </script> <input type="button" onclick="find()"> <table id="tableid"> <tr><td>abcdef</td><td>abcdef</td><td>abcdef</td></tr> <tr><td>abcdef</td><td>abcdef</td><td>abcdef</td></tr> </table>
Bookmarks