I was wondering if it is possible to replace a part of a string with var开发者_StackOverflowiable.
basically what I want to do is the following I want to replace [socialnetworks] with the social network code.
the way it gets the code is via $.POST as it has to fetch this from the mysql database via PHP
You could try something like this.
$("*").each(function () {
if ($(this).children().length == 0) {
$(this).text($(this).text().replace('[socialnetworks]',variable));
}
});
var code = "<p>Something</p>";
yourString.replace("[socialnetworks]", code);
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace
I don't know if it's what you wanted ;).
精彩评论