samedi 25 avril 2015

.splice( $.inArray()) should only remove matching item


I have five links. Each link has an id. I save each of these id's into an array.

When clicking on a link im trying to remove the matching clicked link id from within the array.

Im trying to do this with the following:

shuffledBlockIds.splice( $.inArray(removeItem, shuffledBlockIds), 1 );

The item removes fine with the first click, however if I click again it will simply remove yet another item (although the clicked id no longer exists).

How do I only remove an item, if the clicked id exists in the array?

Had a look at indexOf() but that should supposedly not work in IE8.

IE9+ solution would also be welcomed - just wondering if there's some smart Jquery approach also taking care of IE8.

Fiddle: http://ift.tt/1FlXXMy


Aucun commentaire:

Enregistrer un commentaire