' + sp...">

How to create your own color name

Given the following statement:

$('#upLatImb').append('<span style="color:#F62817; text-decoration:blink">' + sprintf("%11.0f",fCargoLatMom).replace(/ /g,'&nbsp;') + '</span'); 

I would like to do something like:

 var problemcolor=0xF62817; $('#upLatImb').append('<span style="color:problemcolor; text-decoration:blink">' + sprintf("%11.0f",fCargoLatMom).replace(/ /g,'&nbsp;') + '</span'); 

but this leads to numerous html errors.

I could, of course, search and replace all .js files to change the color, but I would like to use logical names, if possible, and change only one statement for each color.

I am only slightly above the absolute beginner level, so all suggestions are welcome.

+4
source share
4 answers

Looks like you want something memorable for reuse?

Create a CSS class with the property "color: # F62817" and apply the class instead of inline styles, which are usually not preferred.

So your CSS:

 .problemcolor { color: #F62817; } .blink { text-decoration: blink; } 

And your jQuery:

 $('#upLatImb').append('<span class="problemcolor blink">' + sprintf("%11.0f",fCargoLatMom).replace(/ /g,'&nbsp;') + '</span'); 

There is no concatenation! This leads to cleaner HTML / CSS and is better suited and remembered immediately.

+7
source

Like this?

 var problemcolor = '#f62817'; $('#upLatImb').append('<span style="color: ' + problemcolor + '; text-decoration:blink">' + sprintf("%11.0f",fCargoLatMom).replace(/ /g,'&nbsp;') + '</span>'); 
+3
source

You can associate your string with something like:

 var problemcolor=0xF62817; $('#upLatImb').append('<span style="color:' + problemcolor + '; text-decoration:blink">' + sprintf("%11.0f",fCargoLatMom).replace(/ /g,'&nbsp;') + '</span'); 
+2
source

Also consider jQuery CSS and appendTo .

 var problemcolor = '#FFFFFF'; $('<span>Your span</span>').appendTo('3upLatImb').css('color', problemcolor); 
+1
source

Source: https://habr.com/ru/post/1382008/


All Articles