Q:

Cannot get jQuery append to work with string

For some inexplicable reason, jQuery append is not working for simple strings.
var donorFormNotValidMsg = "";
var errorMsg = "error occured";

$(donorFormNotValidMsg).append("Error occured");
$(donorFormNotValidMsg).append(errorMsg);

Neither of cases of using append above works, the resulting donorFormNotValidMsg is still just "". Why?

A:

Actually you are working with string not DOM element so, do:
var donorFormNotValidMsg = "";
donorFormNotValidMsg += 'Error occurred';

.appned() will work with DOM element:

var donorFormNotValidMsg = "error occur ";
var errorMsg = "error2 occurred";

$('#append_messages').text(donorFormNotValidMsg);
$('#append_messages').append("<br/>"+errorMsg);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="append_messages">
</div>

Note:- here <div> is a DOM element

