I’m having this trouble: I created a plugin that generates and appends a <div> to my <body>, but this <div> has an id and if I call this functions multiple times my website crashes for obvious reasons, I can’t use a class because I need unique attributes for my appended div, I solved this problem by creating a random number and adding it to my id, like this:
var unique_number = Math.floor(Math.random()*1000001);
var tempImg = '<img id="tempImg'+unique_number+'" src="' + path + ' "/>';
$('body').append(tempImg);
//And I use it like
$('#tempImg'+unique_number).load(function(){ //blabla }
But I’m pretty convinced that this is not the best way of doing this, does anyone have another better/most efficient solution? Thanks.
You can try
lengthproperty: