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? Quote Link to comment 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> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.