-1

I have the following code with which I can change the value of a button while pressing on it:

HTML:

    <input type="submit" value="Submit"/>
    <input type="submit" value="Register"/>

jQuery:

$(":submit").click(function() {
    $("#test").attr("value", "please wait...");
});

I however would like to change the text in a div when pressing a button. So i have:

<body>
    <input type="submit" value="Submit"/>
    <input type="submit" value="Register"/>
    <div id="test"> </div>
</body>

And would like to change the div from "" to please... wait by pressing the submit button:

$(":submit").click(function() {
    $("#test").attr("value", "please wait...");
});

This does not work however. Anybody have an idea what I'm doing wrong?

Stan
  • 8,710
  • 2
  • 29
  • 31
user181796
  • 185
  • 7
  • 22
  • possible duplicate of [HTML/Javascript change div content](http://stackoverflow.com/questions/2554149/html-javascript-change-div-content) – Anish Shah Mar 20 '14 at 09:44

3 Answers3

3

You need to use .text():

$(":submit").click(function() {
     $("#test").text("please wait...");
});

or .html() instead:

$(":submit").click(function() {
     $("#test").html("please wait...");
});

since <div> does not have value, it only has content so .text() or .html() will help you to change the content of <div> elements.

Felix
  • 37,892
  • 8
  • 43
  • 55
0

Use .text()

$(":submit").click(function() {
$("#test").text("please wait...");
});
Anton
  • 32,245
  • 5
  • 44
  • 54
0
<head>
   <script>   
       function f(){   
           document.getElementById("test").innerHTML = "whatever";
       }
   </script>
</head>
<body>

<input type="submit" value="Submit" onclick="f()"/>
<input type="submit" value="Register"/>

<div id="test"> </div>


</body>
Anish Shah
  • 7,669
  • 8
  • 29
  • 40