How to display a message in a clean <div></div!

Asked

Viewed 301 times

-1

How can I display a message in a div that has no content or tag.

Ex: <div class="mensagem"></div>

$msg = "Hello, World";

wanted to display this message of the $msg variable in the div tag, I don’t want to simply use <div class="mensagem">echo $msg;</div>

I need to understand how this works!

  • I couldn’t understand, what you want is to display the PHP variable $msg in div?

  • It is not very clear what you are trying to do. I suggest you set an example closer to what you really need to do.

1 answer

1


If what you want is to display the PHP variable message $msg, you can do it two very simple ways:

Short:

<div class="mensagem"><?= $msg ?></div>

Traditional:

<div class="mensagem"><?php echo $msg; ?></div>

You can also do it using Javascript/Jquery, but I don’t see why you would do it in this example:

<div class="mensagem"></div>

Javascript:

<script>
    document.querySelector('.mensagem').innerText = '<?= $msg ?>';
</script>

Jquery:

<script>
    $('.mensagem').text('<?= $msg ?>');
</script>

You could see:

Video courses that can help you get started:

There are other courses besides these on his channel, this channel is great for those who are starting.

Browser other questions tagged

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