I am trying to use a .each loop to find specific elements in a list that when a custom attribute, “pid”, is not equal to 0 i can perform an action. How can i go about finding each element? so far i have:
$.each($('.container ul li'),function() {
var pid = $('.container ul li').attr('pid');
$(this).remove().after($("container ul li[pid='"+pid+"']"));
});
but this is not doing anything here. can anyone please help?
essentially what i am trying to do is take each element in the list and group them together by the attribute “pid”, so i am searching the list for when the pid does not equal 0, then i need to search it again, and find its match, when each pid is equal to each other, (note: there will only be one match), and append it after the first, or the original.
This will find any
liwith apidthat is not0if that is what you want. It will then start to group the items bypid.This code would produce a list of lists. You can access all of the items with a given
pidby accessinggroups[pid]so all of the items withpid = 5will be ingroups[5].