How to change color in html

Asked

Viewed 71 times

0

I am trying to change a snippet of HTML code to red, but the code below is not right. I thought that color="red" would work. Note: this is html embedded in javascript. When I remove the color snippet, ie color="red", the good wheel code.

var message = "RECOMENDAÇÃO DE AUDITORIA: " + dataRange[i][3] 
      + "<P> -------------------------------------------------</P>" 
      + "<P> *Esta é a Proposta de encaminhamento da Crefiska, de " + dataEnvio + "\n" + ", que deve ser respondida até " + dataFim + ". Para esclarecimentos, consulta o manual e falar com o auditor " + dataRange[i][1]
      +"<HTML><BODY><i><font size=1 color="red"> A finalidade básica da medidas cabíveis (Portaria PRESI 1144/2015, de 02 de Dezembro de 2015)  </font></i></A>" 
      + "</BODY></HTML>";

I have a javascript code that reads data from a google sheet, and sends an alert to an email when the deadline expires. This alert needs to have a stretch in differentiated color, red q eh what I’m trying to do. Everything is working perfectly, except that the color never changes; it is always displayed in black. In the code below, I want the recipient to receive the following in red: "The basic purpose of the audit is to control deadlines. Be attentive to them". He is receiving, but receives black. The complete code is this:

function sendEmails() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 0;  // First row of data to process
  var numRows = sheet.getLastRow();
  var lastCol = sheet.getLastColumn();
      var dataRange = sheet.getRange(2, 1, numRows-startRow,lastCol).getValues();  //Get all values except the header rows


  for (var i=0;i<numRows-startRow;i++){
     var expire = dataRange[i][8]; 

    if (expire < 10) {
      var emailAddress = dataRange[i][7];
      var subject = "Você tem um prazo de auditoria vencendo em " + dataRange[i][8] + " dias";
      //var teste = Utilities.formatDate(dataRange[i][1], "GMT", "dd/MM/yyyy");
      var dataEnvio = Utilities.formatDate(dataRange[i][0], "GMT", "dd/MM/yyyy");
  var dataFim = Utilities.formatDate(dataRange[i][4], "GMT", "dd/MM/yyyy");
      var message = "RECOMENDAÇÃO DE AUDITORIA: " + dataRange[i][3] 
      + "<P> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------</P>" 
      + "<P> *Esta é a Proposta de encaminhamento de " + dataEnvio + "\n" + ", que deve ser respondida até " + dataFim + ". Para esclarecimentos, consulta o manual de auditoria e monitoramento, disponível aqui; entrar em contato com a SESF, pelo telefone 123456 e falar com o auditor " + dataRange[i][1]
      +"<HTML><BODY><i><font size=1> A finalidade básica da auditoria é controlar prazos. Esteja atento a eles. </font></i></A>" 
      + "</BODY></HTML>";

  MailApp.sendEmail(emailAddress, subject, "", {htmlBody: message});
   }

}
}
  • 1

    try with simple quotes color='red'

1 answer

3

The problem is time to use the quotes, if you want to use inside the quote string you need to put this way ", I removed the font tag that is no longer used, and used style instead:

var message = "RECOMENDAÇÃO DE AUDITORIA: " + dataRange[i][3] 
      + "<P> -------------------------------------------------</P>" 
      + "<P> *Esta é a Proposta de encaminhamento da Crefiska, de " + dataEnvio + "\n" + ", que deve ser respondida até " + dataFim + ". Para esclarecimentos, consulta o manual e falar com o auditor " + dataRange[i][1]
      +"<HTML><BODY><i style=\"color: red; font-size: 1px;\"> A finalidade básica da medidas cabíveis (Portaria PRESI 1144/2015, de 02 de Dezembro de 2015)</i></A>" 
      + "</BODY></HTML>";

A simple example for the text to turn red:

//Executa a ação depois que a pagina foi totalmente carregada.
window.onload = function() {

  //Tag i com o texto e a coloração vermelha com fonte com o tamanho de 15px
  var texto = "<i style=\"color: red; font-size: 15px;\"> A finalidade básica da medidas cabíveis (Portaria PRESI 1144/2015, de 02 de Dezembro de 2015)</i>";
  
  //Seto dentro da div "meu_texto" a tag i
  document.getElementById("meu_texto").innerHTML = texto;

};
<div id="meu_texto">
</div>

Try to send this way:

var message = "<P>RECOMENDAÇÃO DE AUDITORIA: " + dataRange[i][3] + "</P>"
      + "<P> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------</P>" 
      + "<P>*Esta é a Proposta de encaminhamento de " + dataEnvio + "\n" 
      + ", que deve ser respondida até " + dataFim + ". Para esclarecimentos, consulta o manual de auditoria e monitoramento, disponível aqui; entrar em contato com a SESF, pelo telefone 123456 e falar com o auditor " + dataRange[i][1] + "</P>"
      +"<P><i style='color: red;'> A finalidade básica da auditoria é controlar prazos. Esteja atento a eles.</i></P>";

Some tags have been removed, such as html and body, which are not required in this example.

  • 1

    Or simply pass style parameters to single quotes.

  • Thanks, but it didn’t work. The String is displayed in black, and it should be red. Did yours display red? q might be wrong?

  • Here it turned red, I don’t know what you’re doing, but the font with 1px isn’t too small? Another thing, because you are using html and body tags to display this message?

  • Still black. I just copied an example from the net. Can I do it differently? How? I don’t understand html. As I am embedding html in javascript, I decided to create a *.html file only with the excerpt below, however, browsers continue to display in black.

  • The code to the new file is this. To answer another question, yes the source must be exactly of this taman, because it is only an explanatory note q I am inserting in the footer. <HTML><BODY><i style="color: red; font-size: 1px;"> The basic purpose of the appropriate measures </i></A></BODY></HTML>

  • If you are going to use html directly, you do not need to put " you have to leave " directly.

  • What exactly do you want to do? What is the purpose of the code?

  • I just want the excerpt "The basic purpose of the appropriate measures" to be displayed in red. That’s all. And it’s not. How and what html code I will use, this is irrelevant.

  • Let’s say it’s for study purposes. I took this code, saved it as a test.html, ran it and it keeps displaying in black this excerpt I told you about. Therefore, I believe that the code is not that, q is missing something. Thankful

  • But do you want to log it into a div? Or is it an Alert?

  • I made a simple example by logging the red text inside a div and put in the answer.

  • I edited the question once again, at the end I posted a new format for you to try to send.

  • Please rate the response and mark as answered.

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.