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

445
Views
How to set margin with jquery?

I am doing this:

var sId=id.toString();
var index=sId.substring(3);
var mrg=index*221;
var el=$(id);
el.css('margin-left',mrg+'px'); and el.css('marginLeft',mrg+'px');

el is the element i want to set the margin to (correctly retrieved) and mrg is the value of the new margin

If i do $('#test1').css('margin-left',200); or $('#test1').css('marginLeft',200); it works in both ways, it's something wrong with the way i set the property.

The correct way is var el=$('#'+id);

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

try

el.css('margin-left',mrg+'px');
over 4 years ago · Santiago Trujillo Report

0

Set it with a px value. Changing the code like below should work

el.css('marginLeft', mrg + 'px');
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!