JoseBazBaz
JoseBazBaz

Reputation: 1445

JavaScript - if #id equals something

Why doesn't the following code work?

        var err = document.getElementById("text-error").value;
        if (err == "Team already exists") {
            $('#text-error').fadeIn(400).delay(3200).fadeOut(800);
        } 

The error does not fade in or fade out.

Checked the console - no problems.

Also, this particular error is sent via the server.

The fade in and fade out work for my client side errors - but not errors pertaining to my database like this one - if that makes any difference to the problem.


UPDATE

After console logging - I realize that it does not enter the if statement, even though it clearly equals it - via html code and via a quick glance at the page.

Upvotes: 0

Views: 20010

Answers (2)

Infinity
Infinity

Reputation: 3875

I am assuming you have something like

<div id="text-error> Team already exists </div>

If so, then replace your first line of code with

var err = document.getElementById("text-error").innerText;

JsFiddle - http://jsfiddle.net/fCNe8/

Upvotes: 2

Omiga
Omiga

Reputation: 581

Try :

 var err = $("#text-error").val();
    if (err == "Team already exists") {
        console.log('is equal but problem is fadeing not working');
        $('#text-error').fadeIn(400).delay(3200).fadeOut(800);
    }else {
        console.log('not equal');
    }

but ofcourse more details about the issue will help us

Upvotes: 2

Related Questions