Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...