1

I'm trying to add a script tag as value of a variable within a script. that is ..

<script>
    $(document).ready(function() {
        var iCnt = 0;
        $('#btAdd').click(function() {
            if (iCnt <= 19) {
                iCnt = iCnt + 1;
                var div = '<div id="node' + iCnt + '" class="item">'+ iCnt +'</div>';
                var jsplmb = '<script> jsPlumb.ready(function() { addPlumb("node'+ iCnt +'") });</script>';
                $('#diagramContainer').after(div);
            }
        });
 });

</script>

which is not working. The close script tag in the variable jsplumb act as the close tag of main script tag.

also the dynamic addition of var div is not adding to

<div id="diagramContainer"> </div>
6
  • also the dynamic addition of html components is not working. pls give a solution for that too.. Commented May 22, 2015 at 7:15
  • BTW, your jsplmb does nothing and is never used. Commented May 22, 2015 at 7:20
  • what about div .. its not working (the html elements are not adding ) Commented May 22, 2015 at 7:22
  • Seems to be working: jsbin.com/ruzumu/2/watch?html,js,output Unless you have the wrong selector #diagramContainer Commented May 22, 2015 at 7:28
  • its showing an warning message : Use of getPreventDefault() is deprecated. Use defaultPrevented instead. Is the problem . Any way its not working even after coping your entire code. But its work in JS Bin Commented May 22, 2015 at 7:40

1 Answer 1

2

The script tags are parsed before the code inside them, so the browser doesn't know that you intended the closing script tag to be a string in the code.

You can break up the closing script tag into separate strings:

var jsplmb = '<script> jsPlumb.ready(function() { addPlumb("node'+ iCnt +'") });</scr' + 'ipt>';
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.