jasonc Posted September 4, 2010 Share Posted September 4, 2010 I wish to know how I can count how many lines there are by searching the innerHTML of a div can anyone suggest how this can be done? Link to comment https://forums.phpfreaks.com/topic/212553-how-to-count-number-of-in-innerhtml/ Share on other sites More sharing options...
The Little Guy Posted September 4, 2010 Share Posted September 4, 2010 <script type="text/javascript"> function countlines(){ var dv = document.getElementById('mydiv').innerHTML; var lines = dv.match(/<br>/ig).length + 1; alert(lines + " lines") } </script> <input type="button" onclick="countlines()" value="# lines" /> <div id="mydiv"> line<br> line<br> line<br> line<br> line<br> line<br> line </div> Link to comment https://forums.phpfreaks.com/topic/212553-how-to-count-number-of-in-innerhtml/#findComment-1107349 Share on other sites More sharing options...
Omirion Posted September 5, 2010 Share Posted September 5, 2010 More on regular expressions. http://www.javascriptkit.com/javatutors/re.shtml Link to comment https://forums.phpfreaks.com/topic/212553-how-to-count-number-of-in-innerhtml/#findComment-1107422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.