How to display a message in a clean div / div! [closed]

-1

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

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

$ msg="Hello World";

I wanted to display this message from the $ msg variable in the div tag, I do not want to simply use <div class="mensagem">echo $msg;</div>

I need to understand how this works!

    
asked by anonymous 01.03.2018 / 05:21

1 answer

1

If you want to display the PHP $msg message, you can do two simple ways:

Short:

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

Traditional:

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

You can also do this using JavaScript / JQuery, but I do not see why you would do this 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 get you started:

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

    
01.03.2018 / 05:55