Я выполняю вызов AJAX, чтобы заменить содержимое моей страницы. К сожалению, это сохраняет весь мой элемент body
с его старыми классами, что портит стиль моей страницы.
Я использую чужой код, который не совсем понимаю:
function loadNewContent(url, bool) {
url = ('' == url) ? window.location.pathname : url;
var newSection = 'cd-'+url.replace('.html', '');
var section = $('<div class="cd-main-content '+newSection+'"></div>');
section.load(url+' .cd-main-content > *', function(event){
// load new content and replace <main> content with the new one
$('main').html(section);
//if browser doesn't support CSS transitions - dont wait for the end of transitions
var delay = ( transitionsSupported() ) ? 1200 : 0;
setTimeout(function(){
//wait for the end of the transition on the loading bar before revealing the new content
( section.hasClass('cd-about') ) ? $('body').addClass('cd-about') : $('body').removeClass('cd-about');
$('body').removeClass('page-is-changing');
$('.cd-loading-bar').one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(){
isAnimating = false;
$('.cd-loading-bar').off('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend');
});
if( !transitionsSupported() ) isAnimating = false;
}, delay);
if(url!=window.location && bool){
//add the new page to the window.history
//if the new page was triggered by a 'popstate' event, don't add it
window.history.pushState({path: url},'',url);
}
});
}
Можно ли изменить этот фрагмент кода так, чтобы он полностью уничтожил старый элемент body
и заменил его новым? Или хотя бы заменить старый атрибут body class
новым?