Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery to remove class from body tag

Tags:

jquery

css

My page is dynamically generating the body class, and it's some WordPress plugin generating. I wanted to easily remove that class, so figured I could strip with jQuery. I thought this would remove the class "page" from the body code which ends up looking like:

<body class="page otherattr otherattr2 etc etc">

By using this jquery in my footer:

<script type="text/javascript">
    $(document).ready(function(){
        $("body").removeClass("page");
    });
</script>

But it doesn't seem to work, am I missing something?

like image 487
916 Networks Avatar asked Dec 12 '11 01:12

916 Networks


People also ask

Which jQuery method is used to hide selected elements?

jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none.

What is jQuery HTML?

jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.

Can you remove a class with jQuery?

Similarly, you can remove the classes from the elements using the jQuery removeClass() method. The removeClass() method can remove a single class, multiple classes, or all classes at once from the selected elements.

Which method is used to remove the class using jQuery?

removeClass() method: This method removes a class in the selector element in jQuery.


1 Answers

$(document).ready(function(){
  jQuery(window).load(function () {
    $("body").removeClass("page");
  });
});
like image 126
Nandhakumar Avatar answered Oct 10 '22 01:10

Nandhakumar