I believe this error is caused by one of two scenarios based on the above information:
This can be solved using the following method:
var pid = ($('#NewPostBody').length && $('#NewPostBody').attr('class')) ? $('#NewPostBody').attr('class') : "";
The ternary operator, together with the truth / falsification logic, should lead either to the returned class or to an empty string. In any case, pid.replace('post-t', '') can be safely called without causing an error.
source share