Problems with concatenations using jQuery, to insert parameters with append

Asked

Viewed 15 times

-1

When placing quotes in different ways to be possible concatenation, an error appears by Elements in the Chromer browser, I would like within the parameters, the information to be with simple quotes. If anyone can help me in this matter of concatenating, it would be a great gratitude.

for(linha = 0;  16 > linha; linha++){
//CARREGAMENTO DOS DADOS LOCAIS DOS FILMES
$('.line_recent').append("<a href='" + filme[linha].src_filme + "' onmouseover='info('"+filme[linha].nome_filme+"', '" + filme[linha].idade_filme + "', '"+ filme[linha].descricao_filme +"','"+ filme[linha].tipo_traducao +"', '"+ filme[linha].ano +"', '"+  filme[linha].capa_filme+"');'><div class='box'><div id='box_img'> <img src='data:image/png;base64, " + filme[linha].img_filme +"'> </div></div></a>");
}

1 answer

1


Take a minute of your time to read about Interpolation is very simple and makes your code more readable, example:

const filme = {
  title: "I'm a movie",
  description: "That's my story",
  release: 2020,
  duration: 220,
  country: "USA"
}

const detalhes = `The movie "${filme.title}" with the history "${filme.description}", was released in ${filme.release} on ${filme.country} with the duration of ${filme.duration} minutes`;

console.log(detalhes);

With interpolation you use the crase which allows you to interpolate text and variables in a simple way without having to add + for each concatenção, it is also easier to use the quotation marks or apostrophe.

  • Thank you so much for the tip! I am very grateful, I will follow these interpolation steps.

Browser other questions tagged

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