Mohan Ram
Mohan Ram

Reputation: 8463

remove class in jquery not functioning

My Code..

            if($("#edButtonHTML").is(".active"))
            {
                $("#edButtonHTML").removeClass("active");
                $("#edButtonPreview").addClass("active");
            }

I need to remove active class from element #edButtonHTML and add to #edButtonPreview Unfortunately not functionating...Help me

Upvotes: 1

Views: 252

Answers (4)

aksarben
aksarben

Reputation: 41

Since you didn't post your HTML, we can't offer a definitive answer. But a couple of suggestions:

  1. Use a JavaScript debugger (I like Firebug) to put a break point inside your "if" condition, to see if code execution ever gets there.

  2. If you're convinced the remove function isn't working, post a question in a JQuery forum, or submit a bug report on the JQuery site.

Upvotes: 0

Carls Jr.
Carls Jr.

Reputation: 3078

My suggestion is do some old school approach. Put an alert statement inside the if statement to see if it was really raised.

        alert("Before if condition.");
        if($("#edButtonHTML").is(".active"))
        {
            alert("Condition was satisfied");
            $("#edButtonHTML").removeClass("active");
            $("#edButtonPreview").addClass("active");
        }

Old school but it works for debugging. But you can use firebug, IEDebugbar or any other browser debugging tool to check if your javascript worked fine.

Upvotes: 0

riffnl
riffnl

Reputation: 3183

Don't think the if-statement will resolve. You can always add an alert statement inside the if to check. Another option to use is hasClass("active"), so

if ($("#edButtonHTML").hasClass("active") {
//go on

Upvotes: 0

Chinmayee G
Chinmayee G

Reputation: 8117

Change your if condition to [assuming active is your class name

 if($("#edButtonHTML").hasClass("active"))
 {
    $("#edButtonHTML").removeClass("active");
    $("#edButtonPreview").addClass("active");
 }

Upvotes: 3

Related Questions