Я работаю над проектом, где мне нужно заменить все вхождения строки другой строкой. Тем не менее, я хочу только заменить строку, если это текст. Например, я хочу включить это...
<div id="container">
<h1>Hi</h1>
<h2 class="Hi">Test</h2>
Hi
</div>
в...
<div id="container">
<h1>Hello</h1>
<h2 class="Hi">Test</h2>
Hello
</div>
В этом примере все "Hi" были преобразованы в "Hello", за исключением "Hi" в качестве класса h2. Я пробовал...
$("#container").html( $("#container").html().replace( /Hi/g, "Hello" ) )
... но заменяет все вхождения "Hi" в html, а также