need too add background color for label?

meera5
Tera Contributor

I want to add background color for label with grey color

1 ACCEPTED SOLUTION

Hi,

this script worked for me in portal

1) onLoad catalog client script

function onLoad(){

	setTimeout(function(){ 
		var aTags = this.document.getElementsByClassName("ng-binding");
		var searchText = "My Label"; // give the text for the label to be searched
		var found;

		for (var i = 0; i < aTags.length; i++) {
			if (aTags[i].textContent.toString() == searchText) {
				aTags[i].style.backgroundColor = 'grey';
				break;
			}
		}
	}, 3000);

}

Output:

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Hi,

this script worked for me in portal

1) onLoad catalog client script

function onLoad(){

	setTimeout(function(){ 
		var aTags = this.document.getElementsByClassName("ng-binding");
		var searchText = "My Label"; // give the text for the label to be searched
		var found;

		for (var i = 0; i < aTags.length; i++) {
			if (aTags[i].textContent.toString() == searchText) {
				aTags[i].style.backgroundColor = 'grey';
				break;
			}
		}
	}, 3000);

}

Output:

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@meera 

Did you get a chance to go through the solution I proposed?

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

If not, please let us know if you need some more assistance.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Maik Skoddow
Tera Patron
Tera Patron

Hi @meera 

I absolutely cannot recommend the proposed solution via DOM manipulation.

You can also achieve this with pure CSS.

See my example:

find_real_file.png

 

For that, you need the value of the "for" attribute of the label tag. Right click on label and then "Inspect" to open the HTML Code inspector of your browser:

find_real_file.png

 

Note the attribute value and close the developer tools.

Then hold CTRL-key and right click anywhere on the page. Then click "Instance in Page Editor"

find_real_file.png

 

Fill in the following CSS defintion at field CSS

find_real_file.png

 

You have to replace the attribute value "sp_formfield_carrier" with your custom value

Kind regards
Maik

Hi @meera 

In case you think I was able to answer your question, I would be happy if you mark the appropriate response as "correct" so that the question will appear as resolved for other users who may have a similar question in the future.

If not, please tell me what you are still missing!

Many thanks & kind regards
Maik