This post may look like a duplicate, but I've tried several ways and it doesn't fix the problem.
I have a DataTable in which I dynamically load HTML tags.
These labels, instead of being like this:
<img src="ruta" />
they are like this:
<img src="ruta"/>
I have made a script in jquery that replaces the characters <
and >
with <
and >
respectively.
The problem is that only the first appearance replaces me, leaving a message like this:
<img src="ruta"/> <img src="ruta"/> <img src="ruta"/> <img src="ruta"/>
My jquery code is as follows
$(".message").each(function(){
var $this = $(this);
var t = $this[0].innerHTML;
$this.html(t.replace('<','<').replace('>', '>'));
});
My HTML is like this:
<div class="message"><img src="ruta"/> <img src="ruta"/> </div>
That div is part of a row of a datatable.
How could I get Datatable to render the HTML tags or JQUERY to substitute characters from ALL messages instead of just the first one.
Thanks.
You're almost done, what you needed was to use a regular expression with the global modifier (
g
)Brief explanation: The method
replace
accepts a string as its first parameter , causing the substitution of the first match or a regular expression. In the case of the regular expression, you can define certain modifiers.Here is an example:
g -> global ( all matches ) i -> ignore case