Сорри, не совсем правильно обьяснила
Цитата:
|
Цитата:
<div id="a1"><span id="b1">text one</span></div> <script> let div = document.querySelector('div'), span = document.querySelector('span'); div.addEventListener('click',()=>{ if (div.id == 'a1') { div.id = 'a2'; span.id = 'b2'; span.innerHTML = 'text two'; return; } div.id = 'a1'; span.id = 'b1'; span.innerHTML = 'text one'; }); </script> |
<style> #a1 { background: white; text-align: left; } #b1 { color: blue; } #a2 { background: blue; text-align: left; } #b2 { color: white; } </style> |
Цитата:
|
Блондинка,
через toggleClass() будет проще <!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style type="text/css"> #a2{ background-color: #0000FF; padding: 5px; } #b2{ background-color: #FF00FF; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> $(function() { $.fn.idToggle = function (arrDivId, arrSpanId) { return this.each(function (i, el) { $(el).click( function () { var c = 0; return function () { c = ++c % arrDivId.length; $(el).attr("id", arrDivId[c]).find("span").attr("id", arrSpanId[c]) } }()); }) }; $("#a1").idToggle(["a1","a2"],["b1","b2"]) }); </script> </head> <body> <div id="a1"><span id="b1">text one</span></div> </body> </html> |
Super !
|
Блондинка,
<!DOCTYPE html> <html> <head> <title>Untitled</title> <meta charset="utf-8"> <style> .a1 { background: white; text-align: left; } .a1 span{ color: blue; } .a1.act { background: blue; text-align: left; } .a1.act span{ color: white; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script> $(function() { $(".a1").on("click", function() { $(this).toggleClass("act") }) }); </script> </head> <body> <div class="a1"><span>text one</span></div> </body> </html> |
Цитата:
|
laimas,
а можно похожий вопрос? есть <div id="animation"></div> как сделать обновление дива по клику(запустить повторно анимацию) без перезагрузки страницы, оговорюсь сразу - это не имеет никакого отношения к первому вопросу. |
Цитата:
|
Часовой пояс GMT +3, время: 23:42. |