开发者

Get id's and add to array, delete from array jquery

开发者 https://www.devze.com 2023-01-16 04:13 出处:网络
i have the current .each in my javascript var divs = array(); $(\'.div-item\').each(function(){ var id = $(this).attr(\'id\');

i have the current .each in my javascript

var divs = array();
$('.div-item').each(function(){
   var id = $(this).attr('id');
   divs.push(id);
});

How would开发者_Python百科 I delete an id from the array programmatically?


function deleteId(divArray, id) {
  var idx = $.inArray(id, divArray);
  if(idx != -1)
    divArray.splice(idx, 1);
}

EDITED: to use $.inArray: some versions of IE don't support the indexOf method on arrays.


var list = [4,5,6];
list.splice(1, 1); // Remove one element, returns the removed ones.

list now equals [4,6]

0

精彩评论

暂无评论...
验证码 换一张
取 消