Jump to content

how to count number of <br> in innerHTML


jasonc

Recommended Posts

<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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.