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

286
Views
How to check for first element in JavaScript that has no style of display none?

I have got a list of li elements as I filter data I exclude the unneeded elements by setting the display to none. I would like to check for the first element that has no style of display set to it how can I do this: Example of element with display none:

<li style="display: none;"><a href="#" data-key="81" data-value="Example 1">Data</a></li> 

Example of element that has no attribute of display none:

<li style=""><a href="#" data-key="1" data-value="Example2">Example2</a></li>

My JavaScript Code:

var liValue = $("#UlId").find('li:not([style*="display: none"])').val();

How can I get the first li that is visible.

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

0

If you only want first visible value find and eq(0) is your friend.

var liValue = $("#UlId").find('li:not([style*="display: none"])').eq(0).find('a').text();
console.log(liValue);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="UlId">
  <li style="display: none;"><a href="#" data-key="81" data-value="Example 1">Data</a></li>
  <li style=""><a href="#" data-key="1" data-value="Example2">Example2</a></li>
  <li style=""><a href="#" data-key="2" data-value="Example3">Example3</a></li>
</ul>

about 4 years ago · Juan Pablo Isaza Report

0

you can use this

$('li:visible:first')
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!