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 & Ajax / JavaScript: Cara untuk mendapatkan i ...

JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Cara mendapatkan indeks (posisi dalam grup) dari sebuah objek dengan jQuery?

Posted on 20. Dikirim di 20. Jun, 2009 by Dragos in Coding , JavaScript & Ajax Jun, 2009 oleh Dragos di Coding, JavaScript & Ajax

I've spent some time today figuring out how to obtain that index and finally I've just puzzled it out. Aku telah menghabiskan waktu beberapa hari ini mencari tahu bagaimana mendapatkan bahwa indeks dan akhirnya aku baru saja bingung itu.

Let's say we have a group of objects all containing the class=”house”. Katakanlah kita memiliki kelompok yang berisi objek semua class = "rumah". 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: Sekarang jika kita merujuk ke elemen pertama dalam kelompok dan kami ingin tahu itu indeks (baik itu jelas dalam kasus ini), kami akan menggunakan potongan kode ini:

 var indexOfFirstElement=$('.house').index($('.house:first')); //indexOfFirstElement=0; indexOfFirstElement =$('. var rumah '). ($('. indeks rumah: pertama')); / / indexOfFirstElement = 0; 

So, the code works as follows: we're searching within all elements of a group all grouped by the class=”house” ( $('.house') ). Jadi, kode bekerja sebagai berikut: kami sedang mencari di semua elemen dari kelompok semua dikelompokkan oleh kelas = "rumah" ($ ( '. Rumah')). 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')) ). Sekarang kita sedang mencari indeks jika suatu elemen dalam grup ini, dalam kasus kami ini adalah elemen pertama dari kelompok ($ ( '. Rumah'). ($('. Indeks rumah: pertama '))).

Here's another example to help you better understand how index() works: Berikut contoh lain untuk membantu Anda lebih memahami bagaimana indeks () bekerja:

 $('.house').each(function(i){ $ ( '. rumah'). masing-masing (function (i) (
     if(i==3) alert($('.house').index(this)); //alerts 3, supposing there are 3 or more elements with class="house" if (i == 3) alert ($('. rumah '). indeks (ini)); / / alert 3, seandainya ada 3 atau lebih elemen dengan class = "rumah"
}); )); 

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. Jadi pada dasarnya, jika Anda perlu untuk mengetahui indeks elemen dalam sebuah kelompok, terlebih dahulu Anda harus menentukan grup dan kemudian lulus objek yang Anda butuhkan untuk menemukan indeks sebagai parameter ke indeks () function.

Translate this post Terjemahkan posting ini


Related posts: Related posts:

  1. JavaScript: GIFless animation. JavaScript: GIFless animasi. Animate images,logos with jQuery Bernyawa gambar, logo dengan jQuery
  2. JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Bagaimana jika tidak animasi jQuery api / start?
  3. JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Kirim fungsi sebagai parameter ke fungsi lain (callback)
  4. JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Di mana saya Cari Semua Properti untuk Semua Elemen HTML?
  5. JavaScript: Get anchor from URL JavaScript: Dapatkan jangkar dari URL

    blog comments powered by Disqus blog comments powered by DISQUS