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 अद्यतन Via आरएसएस | ईमेल Get updates via feedburner Get updates via twitter
Home / Coding / JavaScript & Ajax / JavaScript: How to get the i… घर / कोडिंग / जावास्क्रिप्ट और Ajax / जावास्क्रिप्ट: कैसे मैं पाने के लिए ...

JavaScript: How to get the index (position within a group) of an object with jQuery? : जावास्क्रिप्ट कैसे सूचकांक प्राप्त करने की स्थिति एक समूह के भीतर (jQuery के साथ एक वस्तु का)?

Posted on 20. 20 पर तैनात हैं. Jun, 2009 by Dragos in Coding , JavaScript & Ajax जून, 2009 कोडिंग, जावास्क्रिप्ट और Ajax में Dragos द्वारा

I've spent some time today figuring out how to obtain that index and finally I've just puzzled it out. मैंने कुछ समय बिताया है आज पता लगाना है कि कैसे सूचकांक प्राप्त करने के लिए और अंत में मैं सिर्फ यह है हैरान बाहर.

Let's say we have a group of objects all containing the class=”house”. हम कहते हैं कि हम सभी वर्ग युक्त वस्तुओं का समूह है = "घर". 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: अब अगर हम समूह में पहला तत्व को संदर्भित कर रहे हैं और हम यह सूचकांक (अच्छी तरह से इस मामले में स्पष्ट है पता लगाना चाहते हैं), हम कोड के इस टुकड़े का उपयोग करें चाहते हैं:

 var indexOfFirstElement=$('.house').index($('.house:first')); //indexOfFirstElement=0; var indexOfFirstElement =$('. घर '). सूचकांक ($('. घर: पहला')); / / = 0 indexOfFirstElement; 

So, the code works as follows: we're searching within all elements of a group all grouped by the class=”house” ( $('.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')) ). अब हम सूचकांक के लिए देख रहे हो अगर इस समूह के भीतर हमारे मामले में एक तत्व,) यह समूह का पहला तत्व ($ '(घर. सूचकांक है. ($('. घर: पहला'))).

Here's another example to help you better understand how index() works: यहाँ एक और उदाहरण के लिए मदद से आप बेहतर समझ सूचकांक कैसे काम करता है () है:

 $('.house').each(function(i){ $ ( '. घर'). प्रत्येक (समारोह (i) ( 
      if(i==3) alert($('.house').index(this)); //alerts 3, supposing there are 3 or more elements with class="house" अगर (== 3 i) सावधान ($('. घर ') सूचकांक. (इस)); / / 3 अलर्ट, वहाँ जाना चाहिए वर्ग से 3 या अधिक तत्वों के घर = "कर रहे हैं" 
 }); )); 

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. तो बुनियादी तौर पर, यदि आप एक समूह में पता लगाने के एक तत्व के सूचकांक की जरूरत है, तुम पहले समूह को निर्दिष्ट करना चाहिए और फिर से गुजारें वस्तु आप के सूचकांक में खोजने की आवश्यकता सूचकांक एक पैरामीटर के रूप में कार्य ().

Translate this post अनुवाद इस पोस्ट


Related posts: संबंधित पदों:

  1. JavaScript: GIFless animation. जावास्क्रिप्ट: GIFless एनीमेशन. Animate images,logos with jQuery सजीव चित्र, jQuery के साथ लोगो
  2. JavaScript: What if jQuery animation doesn't fire/start? जावास्क्रिप्ट: क्या होगा यदि jQuery एनीमेशन नहीं आग / शुरू कर दिया?
  3. JavaScript: Where do I Find All Properties for All HTML Elements ? जावास्क्रिप्ट: कहाँ मैं सभी HTML तत्वों के लिए सभी गुण मिला?
  4. JavaScript: Send function as a parameter to another function (callbacks) जावास्क्रिप्ट: एक और समारोह callbacks (एक पैरामीटर के रूप में कार्य भेजें)
  5. JavaScript: Get anchor from URL जावास्क्रिप्ट: URL से लंगर जाओ

    blog comments powered by Disqus ब्लॉग टिप्पणियों Disqus द्वारा संचालित