Richa
Richa

Reputation: 3289

Hide Message after few Sec using JQuery

I have a div in which i am displaying a message after login.

This is how i do it

options.waitingForOperator = 'Custom Message';

And then

$('#chat-box-msg').html(options.waitingForOperator);

Now i was trying to hide only the message i.e (options.waitingForOperator) after few second.

I read i can use settimeout, but not understanding how do i use iy to hide just the message

setTimeout(function () {

}, 3000);

I tried a lot but could not succeed.

Can anyone help me, because i am in learning phase of JQUERY

Update

if (chatId === null || chatId === '') {

    if (nametext1 !== '') {
        myHub.server.requestChat(msg);
        $('#chat-box-msg').html(options.waitingForOperator);
    } else {
        alert(");
    }
} else {
    myHub.server.send(msg);
}

Upvotes: 0

Views: 98

Answers (4)

Richa
Richa

Reputation: 3289

This is what i did to solve it.

if (nametext1 !== '') {
               myHub.server.requestChat(msg);
                $('#chat-box-msg').html('<div id=messagediv>' + options.waitingForOperator +'</div>');
                 setTimeout(function () {
                                        $('#messagediv').hide();

                                        }, 3000);

                                }

THanks a lot @Mr7-itsurdeveloper

Upvotes: 0

STEEL
STEEL

Reputation: 10007

you can use empty() which will just clear the inner text or content.

setTimeout(function () {
    $('#chat-box-msg').empty();
}, 3000);

Upvotes: 0

Mr7-itsurdeveloper
Mr7-itsurdeveloper

Reputation: 1631

Don't use keywords

e.g options & dot (.) in options.waitingForOperator

try with .hide in setTimeout

$(document).ready(function() {
    waitingForOperator ='Custom Message';
    $('#chat-box-msg').html(waitingForOperator);
    setTimeout(function () {
        $('#chat-box-msg').hide(waitingForOperator);
    }, 3000);

});

http://jsfiddle.net/s5SUm/

Upvotes: 1

Nick Coad
Nick Coad

Reputation: 3694

setTimeout(function () {
        $('#chat-box-msg').empty();
    }, 3000);

After three seconds, the above code will empty the #chat-box-msg element.

Upvotes: 1

Related Questions