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

138
Views
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 answers
Answer question

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 Report

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 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!