souporserious
souporserious

Reputation: 2157

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.

Upvotes: 4

Views: 949

Answers (1)

Šime Vidas
Šime Vidas

Reputation: 186003

Here:

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

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

Upvotes: 7

Related Questions