Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Не выводит цвет (https://javascript.ru/forum/misc/45076-ne-vyvodit-cvet.html)

Dark_Delphin 13.02.2014 14:49

Не выводит цвет
 
Всем приветы.
Помогите разобраться со скриптом.
Где я мог допустить ошибку, не выводит в блок div сгенерированный цвет.
$("#gencol").each(function (i) {      
  var color = "#"+((1<<24)*Math.random()|0).toString(16);
  $(this).css("background-color",color);
});


<div id="gencol" style="width:100px;height:100px;"></div>

рони 13.02.2014 14:55

Dark_Delphin,
и давно у вас id размножается?

рони 13.02.2014 15:00

Dark_Delphin,
<!DOCTYPE HTML>
<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script>
$(function () {
      $(".gencol").each(function (i) {
          var color = "#" + ((1 << 24) * Math.random() | 0).toString(16);
          $(this).css("background-color", color);
      });
  })
</script>
</head>
<body>
<div class="gencol" style="width:100px;height:100px;"></div>
<div class="gencol" style="width:100px;height:100px;"></div>
<div class="gencol" style="width:100px;height:100px;"></div>
</body>
</html>

Dark_Delphin 14.02.2014 17:24

Спасибо большое.


Часовой пояс GMT +3, время: 10:49.