I am trying to use switch instead of if else , can you help me how to put below code in switch statement , i can't figure it out how to !
var computed = {
idOnly: function() {},
classOnly: function() {},
selectAllElements: function() {},
eitherOne: function() {}
}
Below is where i can not figure out how to put switch statement
if (computed.idOnly(selector)) {
var getById = document.getElementById(selectorArray[1]);
Allelements.push(getById);
} else if (computed.classOnly(selector)) {
var getByClass = document.getElementsByClassName(selectorArray[1]);
computed.selectAllElements(getByClass, Allelements);
} else {
var getByTags = document.getElementsByTagName(selectorArray[0]);
switch (selectorArray.length) {
case 1:
computed.eitherOne(getByTags, Allelements);
break;
case 2:
computed.eitherOne(byId, byClass, byTag, false);
break;
case 3:
computed.eitherOne(byId, byClass, byTag, true);
break;
}
}
Any help will be much more appreciated , Thanks in advance :)
Aucun commentaire:
Enregistrer un commentaire