Reputation: 13661
In my code I have this:
<textarea id="screen" cols="40" rows="20" readonly> </textarea>
which displays the data in the screen
id, obviously.
But when I change it to:
<span id="screen"></span>
or
<div id="screen"></div>
it shows nothing.
Go easy on me i'm a rookie.
this is in my script tag in the head section:
function update()
{
$.post("chat_new_serv.php", {}, function(data){ $("#screen").val(data);});
setTimeout('update()', 3000);
}
$(document).ready(
function()
{
update();
$("#button").click(
function()
{
$.post("chat_new_serv.php",
{ message: $("#message").val()},
function(data){
$("#screen").val(data);
$("#message").val("");
}
);
}
);
});
The new_chat_serv page just outputs the chat text from the database.
Upvotes: 2
Views: 1658
Reputation: 2042
For <textarea>
you can use .val()
, but for <div>
and <span>
you want to use .html()
or .text()
.
Upvotes: 1
Reputation: 54417
val()
will only get/set the contents of input elements (TEXTAREA
included). Use html()
or text()
to get/set the contents of other HTML tags.
From your code:
$("#screen").val(data);
Would become:
$("#screen").html(data);
Upvotes: 4