I have asked related question here.
Now trying to replace many (more then one) plain-text like [make-this-class]
to class like <div class='make-this-class'></div>
and [make-this-class2]
to a class like <div class='make-this-class2'></div>
on same div <div class='this-div-only'></div>
.
Problem is given js replace only one single text, means its not replace others text of same div, when trying to replace text more then one it replace only one text of same div. Example HTML and JS given below.
HTML:
<div class='not-others-div'>
text text [make-this-class] text
</div>
Text text text
<div class='this-div-only'> <!-- this div only -->
text [make-this-class] text [make-this-class2] and [make-this-class3] and 10 text like this <!--trying to replace text more then one-->
</div>
JQuery:
$(".this-div-only").html(function(i, html) {
return html.replace(/\[(.*)\]/, $("<div />", {"class":"$1"})[0].outerHTML)
})
So how to replace many text to a class (10 ten text) of same div of dom elements by jquery ?