How do i add attribute to html tag with jQuery [closed]

I have a html page with <html> tag where I want to add dir="rtl" and lang="ar" attributes using jQuery when user click on arabic language in drop-down.

I tried using $(html).attr("dir","rtl")

But it returns undefined. Can somebody help as I’m new to jQuery

Answer

There is an error on your code, the “html” tag should be written with quotes as folows:

$('html').attr("dir","rtl")