home
themmj.dev

javascript funfacts

Stuff I found out about Javascript while creating this website.

dot-notation vs. getAttribute

If a DOM-object contains a href attribute then it can either be accessed with .href or getAttribute('href'). One might naively assume that these behave the same, but they do not. In case the href attribute contains a relative path (e.g. "../index.html") .getAttribute will return it as such. .href however, will resolve the relative path to an absolute one and return this instead.

brackets instead of braces

During testing of the above oddity, I accidentally used brackets instead of braces in one of my function calls. Instead of an error, this line was just ignored.