lundi 31 mars 2014

JQuery - Using .each() To Change Selected Elements


Vote count:

0




As I'm iterating through a set of HTML elements passed into a function, I'm trying to set a class on certain elements (rel), depending upon a test. After I set the class, the content I'm returning appears not to have been changed. I'm sure there's a basic disconnect in my logic - any guidance on why my changes don't appear?



data:

< ul >
< li title = "ID: 3 " id = "ID1" rel = "departmentgroup" class = "leaf" >
< a href = "#" class = "departmentgroup" rel = "15000_3_16010_relationship_Department-Path" >
< ins class = "departmentgroup" > & nbsp; < /ins>
Floating
</a >
< /li>
< /ul >

function:

newData = $.trim(data);

$.each($(newData).find("a"), function (i, item) {
thisrel = $(item).attr("rel");
if ($('#' + thisrel).length > 0) {
$(item).children().removeClass().addClass('tick');
}
});

$.each($(newData).find("a"), function (x, curr) {
alert($(curr).children().attr("class")); // no changes evident
});


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire