First of all, this is not a javascript question, but Java question. It's about Jodd Jerry, parsing library in Java that looks very similar to jQuery. So all jsfiddle solutions here does not help, and I believe some negative scores on this question are not ok.
Anyway, the @Archer solution is one that can you give a good direction. Here is the java version of the same:
Jerry doc = Jerry.jerry("<p>to<br>{customerDetails}</p>");
doc.$("p").each(new JerryFunction() {
public boolean onNode(Jerry $this, int index) {
String innerHtml = $this.html();
innerHtml = StringUtil.replace(
innerHtml, "{customerDetails}", "Jodd <b>rocks</b>");
$this.html(innerHtml);
return true;
}
});
String newHtml = doc.html();
assertEquals("<p>to<br>Jodd <b>rocks</b></p>", newHtml);
Jerry still does not have html(function)
type of method implemented (it's on todo), so you have to use each
explicitly.
Note that you can not search for #customerDetails
as you don't have any DOM element with this ID. What you could do instead, is to have an empty placeholder div
or a span
like this:
<p>to<br><span id="#custdet">{customerDetails}</span></p>
and then you would be able to do something like you wrote in the question.
Anyway, I would try to solve this in a different way, if possible. If you already have a marker and HTML content, can you simply replace it without parsing?