print variable Java script within HTML

Asked

Viewed 146 times

1

how to print the variable click inside the Html

<script type="text/javascript">
   $(".j_requerimento").click(function(){
     var click = 1;
     $(".j_label_requerimento").append("<span>IMPRIMIR AQUI A VARIAVEL CLICK</span>");});
  </script>

1 answer

1


From what you wrote, just make a small change:

<script type="text/javascript">
    $(".j_requerimento").click(function(){
     var click = 1;
     $(".j_label_requerimento").append(`<span>${click}</span>`);});
</script>

In that case, we use the Template Strings ES6. However, this is not supported in all browsers. Therefore, another option is to use:

<script type="text/javascript">
    $(".j_requerimento").click(function(){
     var click = 1;
     $(".j_label_requerimento").append("<span>" + click + "</span>");});
</script>
  • thank you very much solved my problem !!

Browser other questions tagged

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