Solution 1 :

var node = document.querySelector('[title="40% Discount!"]').style.color = "red";
<div title="40% Discount!">40% off</div>

Solution 2 :

You can set the style properties of an existing element:

const node = document.querySelector('[title="40% Discount!"]') = "red";

More from here

Solution 3 :

In modern Webdevelopment you should not use .style in JS as it adds it as inline-style and as such has the highest specificity weight that only get overwritten by !important. The modern solution should be to add a class.

Use classList.add('class-name') to add a class to that element that contain color: red; instead!

var node = document.querySelector('[title="40% Discount!"]').classList.add('red');
.red {
  color: red;
<div title="40% Discount!">40% off</div>

Problem :

I selected an element by title. From now on I want to update the css of this text. For ex. ‘color: red;’ how should I move on?

var node = document.querySelector('[title="40% Discount!"]');


Comment posted by Rishabh Jain

you can use ` style ` property ` `

Comment posted by wazz

Edited. Watch out, I think my original post mixed up jquery and js.

Comment posted by Murat erdoğan

Thanks alot wazz, that worked perfect!

Comment posted by tacoshy

You should however not use

Comment posted by Murat erdoğan

This one was very usefull for me. Adding class to locked html is saved my day thanks alot Tacoshy!

Comment posted by tacoshy

If that solves the issue for you, then please consider to up-vote it and mark it as an answer.