SoftwareSavant
SoftwareSavant

Reputation: 9767

Message that appears for a second and then dissapears Javascript

Dumb question. I am trying to get a message to appear and dissapear after a couple of seconds. I just thought I would have a timeout function and at the end I would just append an empty string.

setTimeout(function() {
    $('#resultDivSE').append('<b><p style="font:color:rgb(128,0,128)">' + data + '</p></b>');
}, 1000)
$('#resultDivSE').append('');

That doesn't appear to be working. Am I missing something here... Also, How would you set the color of the text?

Upvotes: 0

Views: 125

Answers (5)

muck41
muck41

Reputation: 288

Jquery css can help you set the color of the font: http://api.jquery.com/css/ Use the css property of Color

It looks like you are missing a semi-colon at the end of your setTimeout string. Maybe I am just being clueless here, or am confused with the code snippet, but it seems like you are doing the opposite, and that the html you want appended to your result div will occur after the 1000 milliseconds.

Upvotes: 0

Robot Woods
Robot Woods

Reputation: 5687

Append is ADDING a blank string to the end, you want to replace it, you want .html('')

for color you want $('#resultDivSE').css('color' , '#FF0000') (I think, I don't use jQuery much)

Upvotes: 3

jfriend00
jfriend00

Reputation: 708136

Your logic is backwards. You need to set the message right away and then, in the timeout, clear it. To make a message appear for a second, you would do this:

$('#resultDivSE').html('<b><p style="color: #ff00ff">' + data + '</p></b>');
setTimeout(function() {
    $('#resultDivSE').html("");
}, 1000);

P.S. I've also filled in the proper style value for settings the color of the text.

P.P.S One second is not a very long time for a message to display. You probably want something like 5 seconds.

Upvotes: 1

DaveR
DaveR

Reputation: 2483

The append command adds text to the div you have selected. To clear all the text in the div you would need:

$('#resultDivSE').html('');

To change the colour of the text in css you just use color: so your paragraph tag would look like this:

<p style="color:rgb(128,0,128)">

Upvotes: 1

Matthias
Matthias

Reputation: 13434

Use .html instead of .append. Append will add something to your div, whereas .html will actually change the HTML.

Upvotes: 0

Related Questions