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 Posodobitev prek RSS | Email Get updates via feedburner Get updates via twitter
Home / Coding / JavaScript & Ajax / JavaScript: How to get the i… Domov / Coding / JavaScript in Ajax / JavaScript: Kako priti i ...

JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Kako indeks (položaj v skupini) predmeta s jQuery?

Posted on 20. Objavljeno dne 20. Jun, 2009 by Dragos in Coding , JavaScript & Ajax Junij 2009, ki ga Dragos v Coding, JavaScript in Ajax

I've spent some time today figuring out how to obtain that index and finally I've just puzzled it out. Sem preživel nekaj časa danes poskušal ugotoviti, kako doseči, da indeks in na koncu sem samo zmeden it out.

Let's say we have a group of objects all containing the class=”house”. Recimo, imamo skupino vseh predmetov, ki vsebujejo class = "hišo". 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: Zdaj, če smo se sklicevanje na prvi element v skupini in bi radi izvedeli, da je indeks (tudi to je očitno v tem primeru), bi mi uporabite ta del kode:

 var indexOfFirstElement=$('.house').index($('.house:first')); //indexOfFirstElement=0; var indexOfFirstElement =$('. house "). index ($('. hiša: prva ')); / / indexOfFirstElement = 0; 

So, the code works as follows: we're searching within all elements of a group all grouped by the class=”house” ( $('.house') ). Torej, koda deluje na naslednji način: smo iskanje v okviru vseh elementov skupine vseh združena z class = "hišo" ($ ( '. Hiša ")). 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')) ). Zdaj iščemo indeks, če element v tej skupini, v našem primeru je to prvi element v skupini ($ ( '. Hiša "). Index ($('. hiša: prva'))).

Here's another example to help you better understand how index() works: Tu je še en primer, da vam pomaga bolje razumeti, kako indeks () za dela:

 $('.house').each(function(i){ $ ( '. hiša "). vsakem (funkcija (i) ( 
      if(i==3) alert($('.house').index(this)); //alerts 3, supposing there are 3 or more elements with class="house" if (i == 3) opozorilo ($('. house "). indeksom (ta)); / / 3 razpisov, ob predpostavki, da so 3 ali več elementov z class =" hiša " 
 }); )); 

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. Torej v bistvu, če želite izvedeti indeks elementa v skupino, morate najprej določiti skupine in nato posredujejo predmet, ki ga je treba najti indeks kot parametra za indeks () funkcijo.

Translate this post Prevedi to post


Related posts: Podobni objav:

  1. JavaScript: GIFless animation. JavaScript: GIFless animacije. Animate images,logos with jQuery Animate slike, logotipi s jQuery
  2. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Pošljite funkcijo kot parameter na drugo delovno mesto (callbacks)
  3. JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Kaj če jQuery animacije ne ognja / začeti?
  4. JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Kam Najdi vse lastnosti za vse elemente HTML?
  5. Javascript: How to validate email address with JavaScript? Javascript: kako potrditi e-naslov z JavaScript?

    blog comments powered by Disqus blog comments powered by Disqus