How to add a class to body tag?

后端 未结 7 1028
猫巷女王i
猫巷女王i 2020-12-09 02:08

I want to add a class to a body tag with jQuery.

For example if the URL is http://www.mywebsite.com/about_us.asp, I want add the first five letters, in this case \'a

7条回答
  •  余生分开走
    2020-12-09 02:20

    Something like this might work:

    $("body").attr("class", "about");
    

    It uses jQuery's attr() to add the class 'about' to the body.

提交回复
热议问题