Imagine that we have some divs like that
<div class="row chapter" node="1">Chapter 1</div>
<div class="row section" node="1">Section 1</div>
Ajax accepts array of nodes that must be deleted. I got few questions about this
1) I’m using following function
$.each(result['nodes'], function(column, node)){
$(".row."+column).slideUp("slow").remove();
}
I can’t figure out how to delete by 2 classes and node atribute. How to do that?
2) AFAIK $.each function deletes one by one. Is it possible to delete all at once?
3) How to deal with validation issues? I mean,
Since an object only has key-value pairs, in order to handle two classes and one attribute, you’ll have to change the structure of your JSON. I suggest changing it to [{“class1″:”foo”,”class2″:”bar”,”node”:1}]. With that format, this will work to collect the nodes:
As Joseph stated, your original code will remove the nodes too soon, so you’ll need to put the
remove()in a parameter toslideUp():Sample jsFiddle: http://jsfiddle.net/tSu8z/
Note that there’s really no “one by one” vs. “all at once” distinction. With the code above, jQuery gets the order to slide the nodes up all at once, but internally it will iterate through the nodes. Likewise, the nodes will most likely all appear to be deleted simultaneously, but jQuery is actually iterating through them. The only requirement for it to look simultaneous is for
slideUpto be asynchronous, which it is.