Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
i was not aware to be able to set custom properties. that's cool!
but what is wrong about
function el(v){return document.getElementById(v);}
or are you running out of ids for single elements? or just a proof of concept? -
element.querySelector('[jsv]') is possible, too. It's not only available on the document.
And if you really need custom attributes please use data-jsv. As it is intended do be done. -
Offtopic: have you guys noticed the photos posted on devRant don't look so shit anymore?
-
crisz81915yThis looks like data-dojo-attach-point, if you ever used dojo. Btw it's a good way to structure a document, imo
-
nam178875045yThis doesn't work for elements created dynamically (after the page loads).
It also creates memory leaks: when elements removed, they still referenced therefore cannot be deallocated. -
@nam17887 Dynamic elements will be created in JS and therefore there is no need for this system in that case.
Hand written HTML elements shouldn't be so plentiful that they fill up memory. And you can in fact delete the variables if you are so inclined. -
@nitwhiz I would use the data prefix if it wasn't ugly. The querySelector solution looks very nice
-
@Charon92 I'm eliminating document.getElementById because I hate writing stuff in HTML and then repeating myself in JS. I just want the variables to be there.
Since the function only runs once on page load I am not concerned about speed. -
@erroronline1 I hate writing something in HTML then essentially repeating myself in JS
I wrote this and wonder if it is actually useful. This is a function that eliminates the need for document.getElementById. In the HTML you just set an attribute (jsv) to some value and this scoops that up and puts it in the global scope for you to use.
Neat or shit?
rant