Adding lang="la" attributes to table cells without affecting already hardcoded lang="en" attributes?

Adding lang="la" attributes to table cells without affecting already hardcoded lang="en" attributes?

Hello.

I'm building a Wordpress website about Latin (but this isn't a Wordpress question!). 

I'm building tables directly in the content editor.

I need to add lang attributes to table cells.

My first try was adding latin="la" to all table cells:

  1. $(".my-table td").attr("lang", "la");

This worked fine, but I realised later that certain cells needed to be in English so I installed a plugin that allows the lang attribute (lang="en-GB") to be added to individual cells (i.e. they are hard-coded into the HTML).

However, the jquery overwrites these and replaces them with lang="la" (so all cells remain lang="la").

In order to fix this I Googled around and tried many variations on the following snippet, with no luck:

  1. var attr = $(".mytable td").attr("lang", "en-GB");

  2. if(typeof attr == undefined && attr == false) {
  3.     $(".mytable td").attr("lang", "la");
  4. }

Which I thought meant:

If the value of var attr is not 'lang="en-GB"', replace with with 'lang="la"'.
What happens is that ALL cells now have lang="en-GB".

I've spent a morning trying to fix this and would very much appreciate it if someone could point out where I'm going wrong!

Chris