A.E A.E - 1 year ago 74
Javascript Question

Id variable does not work when I want to use it as reference

var lightcount = 0;
var domElement = $('<div id="L' + lightcount +'" class="col-md-3 col-sm-6 text-center"><div class="rumbox"></div><button id="onoff" type="button" class="btn btn-md btn-success"> ON </button></div>');
var lid= $(domElement).attr("id");


I have a function that creates a new lightbox when clicking a button.
I want the new lightboxes to be places after current one.

I have a variable for the div id that is incremented for every new lightbox.

So instead of
(which actually works),
I want to use my variable lid:
But this does not work.

Answer Source

You could try:

$("#" + lid).after(domElement);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download