Q:

jQuery – Add ID name of element to body class

I'm using jQuery to add the class .in-view to whichever div is currently showing in the viewport (via this jQuery-viewport-checker script).
I want to take the ID name of whichever div currently has the class in-view and add it to the body as a class name.
Here's what I've got so far. I've got as far as adding the active ID to a variable, and seeing if I can output this to the console, but no luck so far! The console just outputs 'undefined'.
jQuery(document).ready(function() {
    jQuery('.mydiv').viewportChecker({
        classToAdd: 'in-view' // This adds the class to any div that is in the viewport
    });
    var activeId = jQuery('.in-view').attr('id');
    window.console&&console.log(activeId, "Active div ID"); // Testing to see if variable contains the ID

});

A:

Your code showing the in-view div is running immediately after you call viewportChecker. Apparently, no .mydiv is in view at that time (or the plugin hasn't had a chance to mark it as in view yet).
I haven't used the plugin, but looking at the docs, you'll want to use the callbackFunction option:
jQuery(document).ready(function() {
    jQuery('.mydiv').viewportChecker({
        classToAdd: 'in-view', // This adds the class to any div that is in the viewport
        callbackFunction: function(elem, action) {
            $(document.body).toggleClass(elem.attr("id"), action === "add");
        }
    });
});

The callback is called with action being "add" or "remove", so I use action === "add" to decide whether to add the class or remove it.

