Check for existence of specific data attribute value
missing )
and $(selector)
should not be put in a if condition. it is always true
even it does not select anything.
if ($('.item[data-index="' + indexVal + '" ]').length) {
try this:
if ($('.item[data-index="' + indexVal + '" ]').length > 0){
}