I was adding div elements to the dom and was giving a dynamically generated id to these divs as below:

$('p').each(
  var divId = Math.random();
  $(this).append('<div id="' + divId + '">Some text</div>');

  $('#' + divId).css({
    //some style 
  });
);

Above code was not working. Whenever something does not work, RTFM. So, I checked up on id selector in jQuery doc and lo behold, chanced on this.

To remove the dot culprit, wrote a simple function as below:

        function getRandomId() {
          return Math.floor(Math.random() * 100000000) + '';
        }
Advertisements