Hi I'm trying to write jQuery replace function that will replace specific text in the HTML to make a class.
I have find jQuery and Html. See this fiddle: http://jsfiddle.net/davidThomas/juTtG/20
It replaces a text character inside the brackets with <b>hello world!</b>
It's good, but I'm trying to replace more different text, like below:
I have Modified jQuery:
// this
var content = $("body").text().replace(/(\[this\])([\s\S]*)(\[\/this\])/gi,'<b>$2</b>');
console.log(content);
$("body").html(content);
// another
var content = $("body").text().replace(/(\[another\])([\s\S]*)(\[\/another\])/gi,'<b>$2</b>');
console.log(content);
$("body").html(content);
// more
var content = $("body").text().replace(/(\[more\])([\s\S]*)(\[\/more\])/gi,'<b>$2</b>');
console.log(content);
$("body").html(content);
Modified HTML:
[this]hello world 1![/this] [another]hello world 2![/another] [more]hello world more![/more]
See modified problem :http://jsfiddle.net/juTtG/384
The problem is it replaces replace one text character inside the <b></b>
I'm trying to replace more different text.
How to make this modified jQuery and HTML work.
Another matter is, is it possible to replace by this:
<div class="body"> Add a [newclass] </div>
To:
<div class="body">Add a <b class="newclass"></b> </div>
I'm hoping someone could give me a couple suggestions as what to try.
Thanks in advance.