How to convert ñ to ñ in javascript

I have found a bunch of solutions to other characters, such as > and & but accented characters such as ñ don’t work with those solutions. For example, this function:

function encodeHTMLEntities(text) {
  return $("<textarea/>").text(text).html();
}

works great with > and & but not ñ (which i want to be converted to &ntilde;

Thanks for any help,
kevin