This is a translated page. The original can be found here: http://iwebdevel.com/2009/06/20/javascript-how-to-get-the-index-position-within-a-group-of-an-object-with-jquery/
UPDATES VIA RSS | Email Aktualizacje pocztą RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / JavaScript & Ajax / JavaScript: How to get the i… Strona główna / Coding / JavaScript i Ajax / JavaScript: Jak uzyskać i ...

JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Jak zdobyć indeks (pozycja w grupie) obiektu z jQuery?

Posted on 20. Zamieszczone w dniu 20. Jun, 2009 by Dragos in Coding , JavaScript & Ajax Cze, 2009 Dragos w Coding, JavaScript i Ajax

I've spent some time today figuring out how to obtain that index and finally I've just puzzled it out. Spędziłem dziś trochę czasu na zastanawianie się, jak uzyskać tego wskaźnika i wreszcie Właśnie zastanawiali it out.

Let's say we have a group of objects all containing the class=”house”. Powiedzmy, że mamy grupę obiektów zawierających wszystkie class = "dom". Now if we are referencing to the first element within the group and we'd like to find out it's index (well it's obvious in this case), we'd use this piece of code: Teraz, jeśli mamy odniesienie do pierwszego elementu w ramach grupy i chcielibyśmy dowiedzieć się, że indeks (no to oczywiste w tym przypadku), którą stosujemy ten kawałek kodu:

 var indexOfFirstElement=$('.house').index($('.house:first')); //indexOfFirstElement=0; var indexOfFirstElement =$('. house '). indeks domu ($('.: pierwsze ")) / / indexOfFirstElement = 0; 

So, the code works as follows: we're searching within all elements of a group all grouped by the class=”house” ( $('.house') ). Tak, ten kod działa w następujący sposób: Szukamy wśród wszystkich elementów grupy wszystkich pogrupowane class = "dom" ($ ( '. House')). Now we are looking for the index if an element within this group, in our case it's the first element of the group ( $('.house') .index($('.house:first')) ). Teraz szukamy dla indeksu, jeśli element w tej grupie, w naszym przypadku jest to pierwszy element grupy ($ ( '. House'). Indeks domu ($('.: pierwszy '))).

Here's another example to help you better understand how index() works: Oto kolejny przykład, aby pomóc lepiej zrozumieć, jak indeks () działa:

 $('.house').each(function(i){ $ ( '. house'). each (function (i) ( 
      if(i==3) alert($('.house').index(this)); //alerts 3, supposing there are 3 or more elements with class="house" if (i == 3) wpis domu ($('. "). index (this)) / / wpisów 3, zakładając, że są 3 lub więcej elementów z class =" dom " 
 }); )); 

So basically, if you need to find out the index of an element within a group, you should first specify the group and then pass the object you need to find the index of as a parameter to the index() function. Więc w zasadzie, jeśli chcesz dowiedzieć się indeks elementu w grupie, należy najpierw określić grupę, a następnie przekazać obiekt musisz znaleźć indeks jako parametr index () funkcji.

Translate this post Translate this post


Related posts: Podobne posty:

  1. JavaScript: GIFless animation. JavaScript: animacja GIFless. Animate images,logos with jQuery Animowane obrazy, logo z jQuery
  2. JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Co zrobić, jeśli jQuery animacji nie ognia / start?
  3. JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Gdzie mogę znaleźć wszystkie właściwości wszystkich elementów HTML?
  4. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Wyślij funkcji jako parametr do innej funkcji (callback)
  5. JavaScript: Get anchor from URL JavaScript: Get kotwicę z adresu URL

    blog comments powered by Disqus blog komentarze powered by Disqus