Показать сообщение отдельно
  #6 (permalink)  
Старый 09.01.2014, 00:54
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,068

cesarr,
вариант с делегированием перекрасит и восcтановит прежний цвет у любого div )))
<!DOCTYPE HTML>
<html>
<head>
  <title>Untitled</title>
  <style type="text/css">
  #w,#z{background:#FF0;border:#000000 1px dashed;display:inline-block}
  div>div{background:#00F;color:#000;width:60px;margin:8px;float:left;border:#000000 1px dashed}
  div>div:last-child{background:#F00}
  div>div:first-child{background:#FFD700}
  </style>
</head>
<body>
<div id="w">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>
<div id="z">
  <div>4</div>
  <div style="background-color: #00FF00">5</div>
  <div>6</div>
</div>
<script>
document.querySelector("body").onclick = function (a) {
    var b = a && a.target || window.event.srcElement;
    if ("DIV" == b.tagName) {
        a.stopPropagation ? a.stopPropagation() : a.cancelBubble = !0;
        a = window.getComputedStyle ? getComputedStyle(b, "") : b.currentStyle;
        a = a.backgroundColor;
        var c, d = b.getAttribute("color");
        b.style.backgroundColor = d ? (c = "", d) : (c = a, "white");
        b.setAttribute("color", c)
    }
};
</script>
</body>
</html>

Последний раз редактировалось рони, 09.01.2014 в 00:58.
Ответить с цитированием