Проблема заключается в том, что вы создаете объект jQuery из строки в html
и изменяете этот объект, но нигде не сохраняете ссылку на него.
Когда вы вызываете $(body).html()
вы добавляете исходную строку , а не объект jQuery, который вы изменили. Таким образом, вам нужно изменить свою логику так:
var html = '<div class="wrapper"><div class="abc"></div></div>';
var $html = $(html); // create the jQuery object and store a reference to it
// alternatively the above can be made in to one line:
// var $html = $('<div class="wrapper"><div class="abc"></div></div>');
if (someData == "YES") {
var newHTML = '<div>hello</div>';
$html.find(".abc").html(newHTML); // amend the jQuery object
}
$(body).html($html); // add the updated HTML to the DOM