Why is my jquery not displaying my div??

Hi, I write a couple of if statement to display error/success messages if their divs have any span tags inside of them:

    if ($("#error").has("span")) {
        $(this).addClass("display").removeClass("hide");
    }
    if ($("#success").has("span")) {
        $(this).addClass("display").removeClass("hide");
    }

Open in new window


But its not working. The divs still have their classes of .hide (display = none), and they are not getting the class .display (display = block).  Anyone know how to make this work??

The Sign Up tab:
http://auroriella.com/login.aspx#signup
FairyBusinessAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
Try :

http://api.jquery.com/length/
http://api.jquery.com/size/
if ($("span","#error").length > 0) {
        $(this).addClass("display").removeClass("hide");
    }
    if ($("span","#error").size() > 0) {
        $(this).addClass("display").removeClass("hide");
    }

Open in new window

0
FairyBusinessAuthor Commented:
nope, its not working. I tried this:

    if ($("span", "#error").size() > 0) {
        $(this).addClass("display").removeClass("hide");
        alert("success");
    }
    if ($("span", "#error").length > 0) {
        $(this).addClass("display").removeClass("hide");
        alert("success");
    }
    if ($("span", "#success").size() > 0) {
        $(this).addClass("display").removeClass("hide");
        alert("success");
    }
    if ($("span", "#success").length > 0) {
        $(this).addClass("display").removeClass("hide");
        alert("success");
    }

Open in new window


Its alerting so its working on some level, but its not removing or adding the classes.

http://auroriella.com/login.aspx#signup

Any ideas??
0
Ovid BurkeConsultant InstructorCommented:
The 'if' condition is already implicit in the jQuery has() filter, so all you need is this:

$('#error').has('span').addClass('display').removeClass('hide');
$('#success').has('span').addClass('display').removeClass('hide');

Open in new window


However, it might be even more efficient (less code) to define only the class to hide the elements, then use this:

$('#error').has('span').show();
$('#success').has('span').show();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FairyBusinessAuthor Commented:
Wow, the one with the least amount of code worked! lol
Thanks!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.