I am using TinyMCE editor and I want to replace a particular text. In tinyMCE, I am fetching the previous content and then replacing it with some variable.
$("input:radio").change(function() {
if ($(this).is(':checked')) {
if (actions[$(this).attr('id')] != 'Pursue') {
$('#primary_firm').val('').trigger('change');
$('#drafting_firm').val('').trigger('change');
}
$(this).parents('.actions').siblings('.conclusions').find('input:checkbox').prop('checked', false);
const oldActionId = window.oldAction;
console.log(oldActionId);
tinyMCE.activeEditor.setContent(tinyMCE.activeEditor.getContent().replace(oldActionId, '<b>' + actions[$(this).attr('id')] + '</b>'));
// Adding comment
// Hide data of other action
if (isMobile) {
$(this).parents('.actions').siblings('.conclusions').css("display", "none");
$(this).parents('div').next('.conclusions').css("display", "block");
}
}
window.oldAction = actions[$("input[type=radio]:checked").attr('id')];
});
Now problem is that, the first time oldActionId is undefined. That is, it is not able to fetch the previous selected radio button value so it shows undefined. Any way to fetch the previous selected value.