Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
Parse style properties in string

I have an style properties string like below

var style='max-width: 125px; height: auto; object-fit: cover; width: 125px; margin-left: auto; margin-right: auto;'

properties can be any. I want to check if max-width includes, and if it includes it will be deleted. But I couldn't resolve problem

 var imgmaxwidth = style;

 if (imgmaxwidth.includes("max-width")) {
   self.$dialog.find('.note-image-attributes-style-maxwidth').val(value of string max-width);
 }

I want to take this max-width value and then delete this property from string.

In final string will be

height: auto; object-fit: cover; width: 125px; margin-left: auto; margin-right: auto;

Thanks in advance

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Try the following:

var style = 'max-width: 125px; height: auto; object-fit: cover; width: 125px; margin-left: auto; margin-right: auto;'
var styleArr = style.split(';')
var res = styleArr.filter(function (value) { 
  return !value.includes('max-width'); 
});
style = res.join(';');
console.log(style);
.as-console-wrapper { max-height: 100% !important; top: 0; }

about 4 years ago · Santiago Trujillo Relatório

0

var style = $('p').attr('style');
var parts = style.split(';');
var newstyle=[];
for (i=0; i < parts.length; i++)
{
    if (parts[i].split(':')[0].toLowerCase().trim() != 'max-width')
    {
        newstyle.push(parts[i]);
    }
}
$('p').attr( 'style', newstyle.join(';'));

I corrected for cases that would be missed if leading or trailing white space, or case issues. (prompted with comments by @Useless Code)

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda