javascript - Simple math addition in JS giving wrong result -


i have strange problem can't head around. try find highest number in list of elements have data-index attribute respective number. when iterating on them, js insists 9 < 10 false.
see fiddle: http://jsfiddle.net/1ztbxbjx/

what i'm doing wrong?

i can't use

for (i = 0; < $('div[data-index]'; i++))

sometimes there numbers out of order in list (eg. 1,2,3,4,5,25,31).

you need parse id, otherwise you're comparing strings. here example using parseint()


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -