last day (14 days later) » 

3:37 AM
0
A: Dynamic accessing of javascript array

K ScandrettIf you only want to append a class to the li occurring after the active li you can do: var addClass = false; for (var i = 0; i < nodesArray.length; i++) { if (addClass ) nodesArray[i].classList.add('ui-state-disabled'); else nodesArray[i].classList.remove('ui-state-disabled'); ...

 
but under the else condition, the items before activeIndex also will be added right?
 
Yes, see the alternative I just posted, to only add a class to the li following it
sorry, just fixed a bug in the code. The classList.add needs to come before addClass = true, or it will apply it to the active li as well
 
Hi Scandrett, updated my question with my click button logic
 
You may also like to put in a classList.remove('ui-state-disabled'); before the add, so that when you click on another li to make it active it will first remove any ui-state-disabled that occur before it in the array
 
Sacrelett, can u add that in my code and update in the answer. I dun really get it sorry
I have updated my question with my button click function. But I can only go one way now. It works perfect, but when go backward by clicking back button the first element near the active one is not getting the class for some reason.
do i need any different implementation for the previous button type clicks?
 
3:37 AM
The logic in the previous is different to the next button. Have it follow similar logic to the next button
 
basically if next, the activeIndex ++ and if previous then activeIndex--
Thats the main diff between these 2 buttons
 
Yes, so the logic should look the same, but you'd have the activeIndex-- instead
but in your previous code you have code like continue and other logic that I don't see the point of (bearing in mind that I haven't look into it in detail).
else if (_btn.BtnType=="previous"){
if (this._activeIndex > 0) {
this._activeIndex--;
}
if (this._activeIndex == 0){
_btn.disabled = true;
_btn.hidden = true; // you may not want to hide the previous button when at the first item?
}
for (let x in this._formBtn){
if (this._formBtn[x].BtnType == "next"){
this._formBtn[x].disabled = false;
this._formBtn[x].hidden = false;
break;
}
}
}
I haven't tested that, but that's the sort of logic I'd have
 
4:06 AM
Updated my answer with that code. Good luck!
 
 
1 hour later…
5:19 AM
Sorry Scarlett I was away
Hi Scarlett u there?
Sorry whats the addClass boolean for?
 

last day (14 days later) »