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 Updates via RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / JavaScript & Ajax / JavaScript: How to get the i… Home / Coding / Javascript dhe AJAX / Java: Si të merrni i ...

JavaScript: How to get the index (position within a group) of an object with jQuery? Java: Si të merrni indeksi (pozitë brenda një grupi) e një objekti me jQuery?

Posted on 20. Dërguar të 20. Jun, 2009 by Dragos in Coding , JavaScript & Ajax Qershor, 2009 nga Dragoskodim, JavaScript dhe AJAX

I've spent some time today figuring out how to obtain that index and finally I've just puzzled it out. Unë kam kaluar disa kohë sot parafytyruar se si për të marrë indeksin dhe më në fund që unë kam veproj vetëm atë.

Let's say we have a group of objects all containing the class=”house”. Le të themi se kemi një grup të objekteve të gjitha përmbajnë klasë = "shtëpi". 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: Tani në qoftë se ne jemi referenca të Elementi i parë në grup dhe ne do të donim që të gjeni tregues (të mirë është e qartë në këtë rast), ne do të përdorim këtë pjesë të kodit:

 var indexOfFirstElement=$('.house').index($('.house:first')); //indexOfFirstElement=0; indexOfFirstElement var =$('. shtëpi '). index ($('. shtëpi: së pari')); / / indexOfFirstElement = 0; 

So, the code works as follows: we're searching within all elements of a group all grouped by the class=”house” ( $('.house') ). Pra, kodi punon si vijon: ne jemi në kërkim në të gjitha elementet e një grupi të grupohen të gjitha nga klasa = "shtëpi" ($ shtëpi. ( '')). 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')) ). Tani ne jemi duke kërkuar për indeksin e në qoftë se një element në kuadër të këtij grupi, në rastin tonë është elementi i parë i grupit ($ shtëpi. ( ''). Index ($('. shtëpi: së pari '))).

Here's another example to help you better understand how index() works: Ja një shembull për t'ju ndihmuar të kuptoni më mirë se si indeks () vepra:

 $('.house').each(function(i){ $ shtëpi. ( ''). secilin (function (i) (
     if(i==3) alert($('.house').index(this)); //alerts 3, supposing there are 3 or more elements with class="house" nëse (i == 3) alert ($('. shtëpi '). indeksin (ky)); / / alarme 3, gjoja ka 3 ose më shumë elementë me klasë = "shtëpi"
}); )); 

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. Pra, në thelb, në qoftë se keni nevojë për të gjetur nga treguesi i një elementi në një grup, së pari duhet të specifikojë grup dhe pastaj kalojnë objekt ju duhet të gjeni tregues si një parametër të indeksit () function.

Translate this post Translate this post


Related posts: Related posts:

  1. JavaScript: GIFless animation. JavaScript: animacion GIFless. Animate images,logos with jQuery Imazhe gjallë, logot me jQuery
  2. JavaScript: What if jQuery animation doesn't fire/start? Java: Çfarë ndodh nëse animacion jQuery nuk zjarr / filloni?
  3. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Send të funksionojë si një parametër të një tjetër funksion (callbacks)
  4. JavaScript: Where do I Find All Properties for All HTML Elements ? Java: Ku mund ta Find All Prona të gjitha elementet HTML?
  5. JavaScript: Get anchor from URL JavaScript: Merrni të ankorohen nga URL

    blog comments powered by Disqus Komentet blog powered by Disqus