1

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.

Dimitri Dewaele
  • 10,311
  • 21
  • 80
  • 127
George
  • 540
  • 4
  • 8
  • 23

1 Answers1

1

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>';
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • thanks. It works. But if there is another script (*on which I don't have access), and it adds the word "Updates" again how I can prioritize the code you wrote? – George Oct 22 '12 at 11:33
  • @Bogh: Well, you can't. That's not how scripts work, they just run when you tell them to run. You have to find out when and why that other script runs, and fix up things after it has run. – Guffa Oct 22 '12 at 12:13