Home > Software engineering >  Jquery want to replace a - in html with a space
Jquery want to replace a - in html with a space

Time:01-07

I've tried a lot of things, and some of them work in console, but when I put them in the page they stop working.

Jquery is loaded on the site, but it will not replace the string. It either gives an error or seemingly silently fails.

$('h1').html($('h1').html().replace('-',''))

This works, but only in console and strips out all of them. I only need the first removed.

$('h1').html($('h1').html().replace('-',''))

CodePudding user response:

Try this please

$('h1:first-of-type').html($('h1:first-of-type').html().replace('-', ' '));
  • Related