Last active
January 21, 2018 17:19
-
-
Save Franckapik/f622628cfb804afa482bba63bd7ea5b3 to your computer and use it in GitHub Desktop.
Multiple ID function to one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById("color-1").addEventListener("click", function() { | |
if (_previous_selected_obj) { | |
colorize("color-1", "mat1"); | |
modeleTable[_previous_selected_obj.origin_name.substring(6, 7)] = "N1"; | |
} else { | |
notify("[WARNING]"); | |
} | |
}, false); | |
HTML | |
<div class="option-content"> | |
<div id="color-1" class="circle"> | |
</div> | |
<div id="color-2" class="circle"> | |
</div> | |
<div id="color-3" class="circle"> | |
</div> |
efdee
commented
Jan 21, 2018
var optionContentElement = document.querySelector('.option-content');
var selectedId = null;
optionContentElement.addEventListener('click', function (event) {
var isCircle = event.target.classList.contains('circle');
var isSelected = event.target.id === selectedId;
if (isCircle && isSelected) {
event.stopPropagation();
selectedId = event.target.id;
colorize(selectedId, 'mat1');
modeleTable[selectedId].origin_name.substring(6, 7)] = 'N1';
} else notify('[WARNING]');
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment