JohnC1 JohnC1 - 5 months ago 14
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

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

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