0

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

1 Answer 1

5

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);
Sign up to request clarification or add additional context in comments.

2 Comments

Wow... can't believe I missed that. Thank you! I'll accept this as the answer when it allows me to.
Btw, JS strings are immutable, so all string methods are non-destructive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.