• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

273
Views
How to get the eq() value?

Is this possible? For me to get the eq() value? For example, if I click the li:eq(2), var x will become 2. Here's the code.

$('#numbers ul li').click(function(){
  x=$(this).eq().val();
  alert(x);
});
about 3 years ago · Santiago Trujillo
3 answers
Answer question

0

The .index()what is this? method will do it.

$('#numbers ul li').click(function() {
  var self   = $(this),
      index  = self.index(),
      text   = self.text();

  alert(text + ' ' + index);
});

Demo: http://www.jsfiddle.net/Y2aDP/

about 3 years ago · Santiago Trujillo Report

0

The answer above is wrong. Index provides a relative value with respect to its siblings. Hence, the value is expected to change.

It should be something like

$('.someClass').click(function(){
    var that_ = this;
    // your logic for this function
    ....
    ....
    var currentIndex = $('.someClass').index(_that);
});
about 3 years ago · Santiago Trujillo Report

0

eq<> index:

scount=$(selector).length;
for(i=0; i<scount; i++){
    $("selector:eq("+i+")").attr("eq",i);
}
$("selector").click(function(){
    alert($(this).attr("eq"));
});
about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error