jquery/javascript: replace string inside of html()?
11,642
Solution 1
Just a regular old replace
should do it. Be careful about »
, it might be written as »
in the markup or something...
breadcrumbs.replace( new RegExp("<strong>»</strong>", 'g'), "something else" );
Solution 2
breadcrumbs.replace("<strong>»</strong>","new string");
or, depending on how you have written the » character
breadcrumbs.replace("<strong>»</strong>","new string");
Author by
matt
Updated on June 29, 2022Comments
-
matt almost 2 years
the following variable …
var breadcrumbs = $('#trail').html();
… contains:
<href="page1/">Page 1</a> <strong>»</strong> <a href="page2">Page 2</a> <strong>»</strong> <a href="page3">Page 3</a>
How can I replace each
<strong>»</strong>
with something else?