I have come up with a solution. You need to touch the document, but it won't affect the document actually because what I do here will be done in backend.
let newElementStr = class1.innerHTML;//Get the content of Class 1 including Class 2
//Create a duplicate of Class 1 Element and hide it.
let newElement = document.createElement('div');
newElement.style.display = 'none';
newElement.innerHTML = newElementStr;
newElement.id = 'new-el';
//Remove the Class 2 Element
let class2Element = document.querySelector('#new-el .class2');
document.remove(class2Element);
let content = newElement.innerHTML;//This is the string you want
document.remove(newElement);//Cleaning up
You don't need to worry about touching the document because all the changes made by this code won't affect the document because they are hidden display: none;
Hope it works for you!