Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

403
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);
});
over 4 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/

over 4 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);
});
over 4 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"));
});
over 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!