<script type="text/javascript" src="toggle-move-class.js">
➥</script>
</body>
</html>
Figure 3.16. Our HTML demo page of div elements in Safari
OurJavaScriptforbothdocumentsisalsothesame.ClickingtheMovebuttontoggles
themovedclassoneachdivelement:
var move = document.getElementsById('move');
move.addEventListener('click', function(e) {
var objs = document.body.querySelectorAll('div');
Array.prototype.map.call(objs, function(o){
o.classList.toggle('moved');
});
});
OurCSSiswheremattersdiverge.TheCSSusedinExampleAfollows:
110 CSS Master