Nick Kahn
Nick Kahn

Reputation: 20078

How to set div value

How do I set the value/text of a div?

<div id="numberOf"></div>

$("#btn").click(function (event) {
  $.getJSON('http://host/myServiceImpl.svc/GetCount?method=?',
    { id '1' },
    function (data) {
      alert(data);
      $("#numberOf").val = data;
    }
  );
});

Upvotes: 9

Views: 54988

Answers (5)

kishan Radadiya
kishan Radadiya

Reputation: 832

if your value is a pure text (like 'test') you could use the text() method as well. like this:

 $('#numberOf').text(data); Or $('#numberOf').html(data);

Both are working fine.

Upvotes: 0

Dean Taylor
Dean Taylor

Reputation: 42011

Text: http://api.jquery.com/text/

$("#numberOf").text(data);

Html: http://api.jquery.com/html/

$("#numberOf").html(data);

Upvotes: 21

craigmoliver
craigmoliver

Reputation: 6562

or

$('#numberOf').html(data);

Upvotes: 3

davidsleeps
davidsleeps

Reputation: 9503

Set the text property...

$("#btn").click(function (event) {
                $.getJSON('http://host/myServiceImpl.svc/GetCount?method=?', { id '1' },
                function (data) {
                    alert(data);
                    $("#numberOf").text(data);

                });
            });

Upvotes: 1

meder omuraliev
meder omuraliev

Reputation: 186562

^ Google gives you everything you need. I would suggest googling before asking.

So to answer, you'd want

$('#numberOf').text(data) 

or

$('#numberOf').html(data)

Upvotes: 14

Related Questions