Wrap SPAN around all numbers in a DIV

前端 未结 1 956
旧巷少年郎
旧巷少年郎 2020-12-07 02:55

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

相关标签:
1条回答
  • 2020-12-07 03:48

    Here:

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

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

    0 讨论(0)
提交回复
热议问题