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

267
Views
JQuery: Closest div that has an ID

How would you write the Jquery to get the closest div that actually has an ID defined?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You should use has attribute selector. This sample should do the work:

$('selector').closest('[id]')
over 4 years ago · Santiago Trujillo Report

0

$(elementToStart).parent().closest('div[id]');

I use the parent() to avoid just getting the element itself.

Example: http://jsfiddle.net/zQRFT/1/

over 4 years ago · Santiago Trujillo Report

0

Look for an id attribute on a div, using the closest method:

$(this).closest('div[id]');

The [id] brackets there is what's called the Has Attribute Selector

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!