문제

If I have an element like:

<a href="javascript:void(0);" id="updates_toggle">0 Updates</a>

Can I remove only the letters dynamically? And it is possible to wrap it in a SPAN?

I need it to be like this:

<a href="javascript:void(0);" id="updates_toggle"><span>0</span></a>

And I would like to not use jQuery, and use only Mootools or pure JS.

Thanks.

도움이 되었습니까?

해결책

Get what's in the element, replace away anything that isn't digits, and put it back wrapped in a span:

var el = document.getElementById('updates_toggle');
el.innerHTML = '<span>' + el.innerHTML.replace(/\D/g, '') + '</span>';
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top