T
T
therekey2017-01-28 16:46:02
JavaScript
therekey, 2017-01-28 16:46:02

How to display a message on the screen instead of a dialog box (alert)?

How instead of a dialog box (alert) to display a message on the screen through <а id="test">а>?

Working example:

$.getJSON('https://minecraftpocket-servers.com/api/?object=servers&element=voters&key=ruc7ov3m2v4w7fqeq6np8fhivep48w', function(data) {
$('#test').html(data.voters.length);
});


Script to change:
$.getJSON('https://minecraftpocket-servers.com/api/?object=servers&element=voters&key=ruc7ov3m2v4w7fqeq6np8fhivep48w', function(data) {
  var votes = 0;
  for(var i=0; i<data.voters.length; i++){
    votes += JSON.parse(data.voters[i].votes)
  }
  alert(['голосов: ' + votes, ' проголосовавших: ' + data.voters.length]);
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-01-28
@therekey

$.getJSON('https://minecraftpocket-servers.com/api/?object=servers&element=voters&key=ruc7ov3m2v4w7fqeq6np8fhivep48w', function(data) {
  var votes = 0;
  for(var i=0; i<data.voters.length; i++){
    votes += JSON.parse(data.voters[i].votes)
  }
  $('#someDivId').html('голосов: ' + votes + ' проголосовавших: ' + data.voters.length);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question