0

Using jQuery

  $(document).ready(function() {
  $("#pid1").removeClass("login_page");
  });

HTML

<body  class="login_page" id="pid1" ng-app="myApp" ng-controller="myCtrl">

In the main page class gets removed but login page also remove class but I have to keep the class in the login page.

loginpage.html

<div class="login_page">
</div>

when I add remove class function it's work and I have tried to keep the login_page class in loginpage.html.

7
  • 1
    i did not get your question, you want to remove login_page class for body where id='pid1' and not from others right? but that id is getting repeated in some other pages? Commented Sep 7, 2018 at 5:02
  • Your question is unclear, the code you posted is fine, what do you want to do differently? Commented Sep 7, 2018 at 5:05
  • Change the id in your login page. Or write your script only in the main page. Commented Sep 7, 2018 at 5:06
  • @Esko it's simple index page remove class but I have to keep the class in the login page. Commented Sep 7, 2018 at 5:14
  • @TalkNit id not given in login page only given in the body of the index page. Commented Sep 7, 2018 at 5:15

3 Answers 3

1

This will work for you:

In below code .login_page_class can be your class which is present only in your login page.

$(document).ready(function() {
  if($(".login_page_class").length == 0){
   $("#pid1").removeClass("login_page");
  };
});

Added a condition to check if .login_page is present in the page and if it is then don't execute the code.

Hope this was helpful for you.

Sign up to request clarification or add additional context in comments.

7 Comments

if``$(".login_page").length == 0` is true then you will never remove class as there is no such element present
@Rushidave Sorry, I have updated the code, please check. I misplaced the class.
I updated but not working index and log in both page remove class
@Rushidave did you add only to login page.? please add a new class only to the login page and replace .login_page_class with the class you added in the login page and it will work.
@weBBer yes, only login page . in the login page, I replaced class but not working.
|
1

The simple solution for this is below which will remove the body class on load.

window.onload = function () { document.body.className = ""; }

If you do have concern with other lib then you can try below solution as well.

window.addEventListener( 'load', function load() { window.removeEventListener('load', load, false); document.body.classList.remove('preload'); }, false );

Using addEventListener means that it won't interfere with any other event listeners that may be attached by other libs, etc.

The above code will remove the event listener once the event has fired too.

2 Comments

@ Rahul Dhmecha I already tried this solution but it's shown same error btw tx for the response.
@Rushidave Which angular version you are using. Try nginit and remove class at this stage will help you to add and remove the class.
0

I solved this issue and its' work for me,

add and remove class manually in index controller and login controller, I remove class function in the index page and added class function in the login page.

Remove function

       $(document).ready(function()
         {
          $("body").removeClass("login_page");
        });

Add function

    $(document).ready(function()
      {
       $("body").addClass("login_page");
      });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.