Coder Social home page Coder Social logo

Comments (4)

pie6k avatar pie6k commented on May 22, 2024

I think concept of element index is not relevant here as it's calling this callback as soon as element has appeared on the screen, so it has no context of 'group' like map or each has.

Consider such case

Initially you have 5 .element divs
Then you add 2 more .element divs
Then you remove 3 of existing .element divs
Then you add one more ----> what would you expect now to be i inside this function?

from jquery.initialize.

IrvingArmenta-ML avatar IrvingArmenta-ML commented on May 22, 2024

I will expect the same result I get using $.each or $.map , to get the actual length of the elements that are exactly at that time in the DOM, in your example:

5 .element divs (0,1,2,3,4)
add 2 = 7 .element divs (0,1,2,3,4,5,6)
remove 3 = 4 .element divs (0,1,2,3)
add 1 = .element divs (0,1,2,3,4)

You can do this by setting a function with $.each and run a function to "read" again the elements in the DOM, but that is exactly what I want to $.initialize to do for me, I don't want to set up a function to update the list of elements.

from jquery.initialize.

bezborodow avatar bezborodow commented on May 22, 2024

An iterator doesn't exactly make sense in this context since elements can be inserted into the DOM out of order, and also can appear in complex or nested trees, not just as siblings.

If you are insistent on this, you can off course do:

var i = 0;
$.initialize('.element', function(el) { 
  console.log(i);
  i++;
});

Although I understand that it may make sense to have an iterator in some circumstances, nobody has asked for such a feature to date. I wonder for the sake of curiosity what your scenario is that you need this for?

from jquery.initialize.

bezborodow avatar bezborodow commented on May 22, 2024

Wontfix.

from jquery.initialize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.