Home javascript jQuery interrupt continuation for inside Each only for this cycle

jQuery interrupt continuation for inside Each only for this cycle

Author

Date

Category

I need that the FOR cycle stops working if IF condition gave False. In this case, the Each cycle worked on for the elements

$ ('. Item'). Each (function () {
  var NextItems = $ (this) .Parent (). NextALL () // Take all the elements that after the parent
  $ (this) .Parent (). After ('& lt; div class = "ingredient-item-wrap" & gt;') // Create div and insert after your parent
  var newwrap = $ (this) .Parent (). Next (). First (); // Select the created above
  For (var i = 0; I & lt; nexTiTems.Length; i ++) {// Cycle for all elements that are after the parent
    If ($ (NextItems [i]). Find ('. Item'). length == 0) {// If the element does not have inside the sofa with the class, then we perform the script below
      if ($ (NextItems [i]). Hasclass ('WC-PAO-Addon-Container')) {// If the next item has a class, then we perform the script below
        newwrap.append ($ (NEXTITEMS [I])); // insert this block into the wrapper
      }
    } else {// if the element inside has a WC-PAO-Addon-Heading class, then go below
      RETURN FALSE // stops both cycles, must stop this for
    }
  }
})

The script works correctly, only for the first .item , turns on.
Please tell me


Answer 1

if (nextitems [i]). Find ('. Item'). length == 0) {
 ...
} else {
 Break;
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions