We can escape these kind of characters like single quotes can be escaped using backslashes.
Ex :-
"D'souza" can be written as "D\'sauza".
If the same text is being used in selector text we can use double backslashes to escape the single quote.
Also you can use regular expressions to escape characters to any string having single or double characters as :-
var strReplaced = strToReplace.replace(/(['"])/g, "\\$1");
Hope this will be of help.