JohnC1 JohnC1 - 1 year ago 78
jQuery Question

Use $(Selector) without jQuery

I am currently using something like this:

function Select(query)
return query[0] === '#' ? document.querySelector(query) : document.querySelectorAll(query);

I have to use it like:

Select('#id').innerHTML = "content", or Select('.class')

Is there a way I can use $('#id) or $('.class') without jQuery?

Answer Source

Add window.$=Select or change name of function to $

This won't enhance any capabilities...just shorten the code when you use it