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

148
Views
Excluding certain elements from Array.prototype.indexOf.call
var el = clickedElement;
var chl = el.closest('li');
var prt = chl.parentNode;
var idx = Array.prototype.indexOf.call(prt.children, chl);

Im using this code to get the index number of clickedElement from the parentNode.. it works most of time.. i want to be able to filter out some elements from the index number

For example..

li.zero
li.first
h2
li.second

If I try this code to get li.second element as index 2 it gives me index '3' because of that h3 tag inbetween.. How can i exclude certain elements from counting?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could use the Array.prototype.filter method.

It might look something like this:

var idx = Array.prototype.indexOf.call(
  Array.from(prt.children)
    .filter(domNode => domNode.tagName.toLowerCase() === "li"), 
  chl
);

Now you will only check the index for list item elements.

about 4 years ago · Juan Pablo Isaza 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!