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'
)
Written by Lee
Related protips
1 Response
What the fuck did I just read
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
iam4x
94.17K
ericdfields
63.02K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#