Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function myFunction()
- {
- // Page elements
- var blokArray = document.querySelectorAll(".block");
- var button = document.getElementById("btnAddBlock");
- var divBlokken = document.getElementById("divBlokken");
- // Variables
- var blokArrayLength = blokArray.length;
- // Change stage of .block elements when clicked
- for( var i = 0 ; i < blokArrayLength ; i++ )
- {
- blokArray[i].addEventListener( "click", function()
- {
- if( this.classList.contains("stage1") )
- {
- this.classList.remove("stage1");
- this.classList.add("stage2");
- }
- else if( this.classList.contains("stage2") )
- {
- this.classList.remove("stage2");
- this.classList.add("stage3");
- }
- else if( this.classList.contains("stage3") )
- {
- this.classList.remove("stage3");
- this.classList.add("stage1");
- }
- else
- {
- }
- });
- }
- // Button functionality
- button.addEventListener( "click", function()
- {
- // Create new row div
- var newRowDiv = document.createElement("div");
- newRowDiv.classList.add("row");
- divBlokken.appendChild( newRowDiv );
- // Create new block div
- var newBlockDiv = document.createElement("div");
- newBlockDiv.classList.add("block");
- newBlockDiv.classList.add("stage1");
- newRowDiv.appendChild( newBlockDiv );
- // Add click event to new .block element
- newBlockDiv.addEventListener( "click", function()
- {
- if( this.classList.contains("stage1") )
- {
- this.classList.remove("stage1");
- this.classList.add("stage2");
- }
- else if( this.classList.contains("stage2") )
- {
- this.classList.remove("stage2");
- this.classList.add("stage3");
- }
- else if( this.classList.contains("stage3") )
- {
- this.classList.remove("stage3");
- this.classList.add("stage1");
- }
- else
- {
- }
- });
- });
- }) ();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement