-2

I use this to take the name of the body class:

$("body").attr("class")

In source code I can see this:

<body class="mybodyclass">

but when I use the first command in console I take this:

"mybodyclass wrap-in wrap-out"

From the result how it could be possible to take the first word only?

therin
  • 73
  • 8
  • You could split by spaces class attribute and shift it but **why** would you need that??? `var firstClass= $("body").attr("class").split(' ').shift();` – A. Wolff Nov 16 '15 at 12:46

2 Answers2

0

Just like in this question, the quickest solution is to split the result, like this:

$("body").attr("class").split(' ')[0];
Community
  • 1
  • 1
Squirrel
  • 392
  • 7
  • 15
-1

Look at .removeClass() And .addClass()

You can use

var class = $("body").attr("class").split(' ')[0];
$("body).removeClass().addClass(class)';`
Dreamwalker
  • 3,032
  • 4
  • 30
  • 60
ahervin
  • 461
  • 2
  • 15