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

182
Views
Is there a simple way to add a variable string to an element attribute without "setAttribute"?

I'm trying to take data from another part of the element and add it to another (force lazy-loading images to load) and everything I find points me towards setAttribute however this breaks the data as it automatically adds a equals and quotations to the added data which breaks it.

So:

images[i].setAttribute('data-anim-src',' srcset= "'+images[i].getAttribute('data-srcset')+'"');

Gets me data-anim-src=" srcset="..."" instead of what I want which is data-anim-src srcset="..."

Is there any way to remove the ="" that's automatically added with setAttribute? or is there an equally simple alternative?

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

0

setAttribute works like this:

setAttribute(attribute, value);

not like this:

setAttribute(attribute1, attribute2, attribute3);

So to solve it, just set them separately:

images[i].setAttribute('data-anim-src', 'true');
images[i].setAttribute('srcset', images[i].getAttribute('data-srcset'));
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!