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

177
Views
dom element data attribute append if not exist

I am adding custom data attributes to div. Every time child is clicked it will add value to 'data-selected' attribute to parent (if not already exist), for example:

<div class="parent">
     <div class="child" title="a"></div>
     <div class="child" title="b"></div>
     <div class="child" title="something rather"></div>
     <div class="child" title="foo"></div>
</div>

var parent = $('.parent')

$(document).on('click', '.child', function(){
     var title = $(this).attr('title')

    //parent.attr('data-selected', title)
})

I know I can get parent attributes on child click, split them into array and compare values manually if already exist, but I am wondering is there a direct method which can do this?

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