Wrap SPAN around all numbers in a DIV

一笑奈何 提交于 2019-12-28 07:04:27

问题


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.


回答1:


Here:

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

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



来源:https://stackoverflow.com/questions/11067726/wrap-span-around-all-numbers-in-a-div

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!