How do I iterate through children elements of a div using jQuery?

后端 未结 7 1487
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 01:28

I have a div and it has several input elements in it... I\'d like to iterate through each of those elements. Ideas?

7条回答
  •  青春惊慌失措
    2020-11-28 02:00

    I don't think that you need to use each(), you can use standard for loop

    var children = $element.children().not(".pb-sortable-placeholder");
    for (var i = 0; i < children.length; i++) {
        var currentChild = children.eq(i);
        // whatever logic you want
        var oldPosition = currentChild.data("position");
    }
    

    this way you can have the standard for loop features like break and continue works by default

    also, the debugging will be easier

提交回复
热议问题