RussellHarrower
RussellHarrower

Reputation: 6800

jQuery replacewith

I was wondering if it is possible to replace a part of a string with variable.

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

Upvotes: 0

Views: 147

Answers (2)

Przemek
Przemek

Reputation: 6700

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 ;).

Upvotes: 1

Jonas m
Jonas m

Reputation: 2734

You could try something like this.

$("*").each(function () { 
if ($(this).children().length == 0) { 
  $(this).text($(this).text().replace('[socialnetworks]',variable)); 
   } 
});

Upvotes: 2

Related Questions