DEV Community

Discussion on: Who still regularly uses jQuery?

Collapse
 
pavelloz profile image
Paweł Kowalski

Fun fact

If you need to access element via ID, then you can skip functions altogether.

Having element: <div id="my-element"></div> you can access it via window["my-element"] ;-)

Collapse
 
jackharner profile image
Jack Harner 🚀

That is a fun little fact.

Good to know!

Collapse
 
karataev profile image
Eugene Karataev

It's not always safe to use this trick to query an element. For example, if you have <div id="alert" /> on a page, accessing window['alert'] will not return the element you're looking for.