add id to dynamically created

后端 未结 6 2146
鱼传尺愫
鱼传尺愫 2020-12-23 18:48

I have the following JavaScript that creates a div and then appends it to the body and then inserts some dynamically generated HTML into it. cartDiv = document.createElement

6条回答
  •  执念已碎
    2020-12-23 19:45

    You can add the id="MyID123" at the start of the cartHTML text appends.

    The first line would therefore be:

    var cartHTML = '
    ';

    -OR-

    If you want the ID to be in a variable, then something like this:

        var MyIDvariable = "MyID123";
        var cartHTML = '
    '; /* ... the rest of your code ... */

提交回复
热议问题