Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

446
Vistas
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 Respuestas
Responde la pregunta

0

try

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda