Wrap SPAN around all numbers in a DIV

I am trying to wrap a span around all numbers in a div so I can style them accordingly.

I have searched for some javascript to do this with no luck on being able to target all the numbers within the div.

It will be for Bible verses that will be copied and pasted into a textarea. I would like to style all of the numbers within that. Similar to how this site does here: http://marshill.com/media/trial/trial-and-jesus#scripture

Under the "Scripture" tab.

Answers:

Answer

Here:

elem.innerHTML = elem.innerHTML.replace( /\b(\d+)\b/g, '<span>$1</span>' );

Live demo: http://jsfiddle.net/ujA86/

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.