Here is what I am trying to do
Fox<span>Rox</span>
before that
FoxRox
How do I wrap spans around Rox
?
Here is what I am trying to do
Fox<span>Rox</span>
before that
FoxRox
How do I wrap spans around Rox
?
This will search you whole DOM and replace each Rox
with <span>Rox</span>
:
$(':contains("Rox")').html(function(index, oldHTML) {
return oldHTML.replace(/(Rox)/g, '<span>$&</span>');
});
In this case, you could use the JavaScript replace()
method:
'FoxRox'.replace(/(Rox)/, '<span>$1</span>');
To replace this all through the document, you could try the following:
$(":contains('Rox')").html(function(i,o){
return o.replace(/(Rox)/g, '<span>$1</span>');
});
Note, if your term is not "Rox", you'll need to change it in the above script.
KllD
with Rox
you will see what I mean. So I want something like this 'FoxKllD'.replace(/(KllD)/, '<span>Rox</span>');
. Also, On chrome console it said Unexpected token ILLEGAL. –
Cosette "<span>Rox</span>"
? –
Rondeau © 2022 - 2024 — McMap. All rights reserved.