1

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

2
  • Are you sure your if condition is satisfied? Put alter statements to check this Commented Dec 2, 2010 at 9:08
  • have you checked it using a browser debugging tool like firebug if the class was really removed? Or did you check that the condition really went inside the if statement? Commented Dec 2, 2010 at 9:16

4 Answers 4

3

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

 if($("#edButtonHTML").hasClass("active"))
 {
    $("#edButtonHTML").removeClass("active");
    $("#edButtonPreview").addClass("active");
 }
Sign up to request clarification or add additional context in comments.

3 Comments

Its not working for me even i used hasClass i am using newer version of jquery.
actually .hasClass("active") is a better way for checking a class but .is(".active") also works. I think the question here is, was the condition satisfied or is the element with edButtonHTML that has a class named active found in the page.
Yes that is true. My First comment is the same question
0

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

Comments

0

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.

2 Comments

It shows alert but i doesnt remove class. I heard that jquery new version not function properly sometimes using removeClass
jQuery JavaScript Library v1.4.2
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.