A
A
Anton2018-01-31 23:43:06
JavaScript
Anton, 2018-01-31 23:43:06

How to display alert in div?

<script>
// Это json который пришел
var json = '<?php echo $s;?>';
// Здесь парсим json
var data = JSON.parse( json );

// Здесь получаем нужное свойство
alert( data.icestats.source.title );
</script>

the contents of the alert brackets appear in the pop-up window of the browser, how to output and insert into the page in the right place in the div?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VelAnna, 2018-01-31
@anton99zel

Do you want the alert content to be added to a block on the page?
If the block has already been created, for example, then pure js:

<div id="div-name"></div>
<script>
var myDiv= document.getElementById('div-name'), 
json = '<?php echo $s;?>',
data = JSON.parse( json );

myDiv.innerHTML = data.icestats.source.title;
</script>

On jquery:
$('#div-name').html(data.icestats.source.title);

S
St1myL, 2018-01-31
@St1myL

As far as I know (may be wrong), alert cannot be displayed in blocks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question