Set attribute without value
Perhaps try:
var body = document.getElementsByTagName('body')[0];
body.setAttribute("data-body","");
The attr()
function is also a setter function. You can just pass it an empty string.
$('body').attr('data-body','');
An empty string will simply create the attribute with no value.
<body data-body>
Reference - http://api.jquery.com/attr/#attr-attributeName-value
attr( attributeName , value )