Jquery / javascript: replace string inside html ()?

next 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?

+3
source share
2 answers

Just plain old replaceshould do it. Be careful with », it can be written as &raquo;a markup or something like that.

breadcrumbs.replace( new RegExp("<strong>»</strong>", 'g'), "something else" );
+15
source
breadcrumbs.replace("<strong>»</strong>","new string");

or, depending on how you wrote the character

breadcrumbs.replace("<strong>&raquo;</strong>","new string");
+5
source

All Articles