String.prototype.replace
is non-destructive. It doesn't change the original string, but creates a new one. You want this:
section = section.replace(/COUNT_KEY/g, i);
Question
I am working on a plugin for WordPress and I need to add multiple settings to be able to add multiple videos. Everything is working except for when I copy the content in the script tag, I am not able to replace a placeholder with the value I want.
Here is what I have so far: http://jsfiddle.net/Jb6NK/1/
(function ($) {
var i = 0;
$("#add-olympvm").click(function () {
var section = $("#blank_data").text();
section.replace(/COUNT_KEY/g, i);
$("#olympvm_cage tbody").append(section);
i++;
});
}(jQuery));
What I am trying to do is replace COUNT_KEY
with the value of i
.
I know this is possible but for the life of me I cannot seem to get this working.
Any help/pointers is much appreciated.
Thanks,
Jeremy
Solution
String.prototype.replace
is non-destructive. It doesn't change the original string, but creates a new one. You want this:
section = section.replace(/COUNT_KEY/g, i);