Last Updated: September 09, 2019
·
1.607K
· geetotes

Write arbitrary parameters in HTML tags using Javascript with this one weird trick

Teen moms have discovered this one weird trick to writing arbitrary parameters to the DOM!

Even weirder, this strange trick demonstrates some properties of Javascript that the government doesn't want you to know!

Across the country, insurance companies try to write an anchor tag like this:

<a href="#foo" data-toggle="modal">Popup</a>

And an eccentric billionaire tried to use jQuery to simply write that tag to the DOM

foo = $('<a>',
  text: 'bar'
  data-toggle: 'modal'
  href: '#foo'
)

The eccentric billionaire was also using coffeescript.

But local police learned how to evade speeding tickets and the javascript would throw an error: data- is undefined.

Then a stay-at-home mom saved thousands of dollars on her dentist bill by using this one weird trick to encapsulate keys on an options hash

foo = $('<a>',
  text: 'bar'
  'data-toggle': 'modal'
  href: '#foo'
)

1 Response
Add your response

What the fuck did I just read

over 1 year ago ·