/ Gists / unique selector in document (while)
On gists

unique selector in document (while)

JavaScript

unique.js Raw #

/*!
 * getUniqueClass - v1.1 - 2/13/2010
 * http://benalman.com/projects/jquery-misc-plugins/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */

// For when you really need a unique classname, (like when you're cloning a
// whole bunch of elements and don't exactly know where they're going, but need
// to do something with them after they've gotten there).

jQuery.getUniqueClass = function() {
  var name, i = 0;
  while ( jQuery('.' + (name = 'BA-' + (+new Date) + (i++))).length ) { };
  return name;
};



// 2 my

let s = '.test'
let name, i = ''
while (document.querySelector(name =  s + i)) {
  i += 0
  i++
}

document.write(name)