My goal is to add/replace new classes to body
, dynamically provided by the "id" variable below. That variable's value is the actual id
of each section
that passes into the viewport on scroll. So as different sections
(obviously with different ids
) pass through the viewport, they pass their id
name to the body
as a new class
, adding a new or replacing the previous class
. Using toggleClass
with the boolean true
, it works, but it's also replacing all of the other classes on the body
tag, given inherently by the Wordpress template, which of course is breaking everything else. Make sense? Any insights would be helpful.
var id = entry.target.getAttribute('id');
var newClass = $('body').toggleClass(id, true);