Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Is element.addEventListener universal or do I need jQuery?

JosiahMaybe

Gold Coder
In HTML pages there are elements and these elements can have event listeners.
Like most universal way I have found to set these is element.addEventListener with first parameter for what and second parameter listener.
Is say like that with "click" universal?
Like could it run on all internet browsers?
Would jQuery be more universal like that?
Is anything really universal like that?
If so please tell me.
I found that getElementById is not universal, it does not support older browsers, but on modern browsers, universal.
X E.
 
Last edited:
Solution
In HTML pages there are elements and these elements can have event listeners.
Like most universal way I have found to set these is element.addEventListener with first parameter for what and second parameter listener.
Is say like that with "click" universal?
Like could it run on all internet browsers?
Would jQuery be more universal like that?
Is anything really universal like that?
If so please tell me.
I found that getElementById is not universal, it does not support older browsers, but on modern browsers, universal.
X E.
addEventListener should work fine without jquery.
as far as selecting elements... you could just use document.querySelector('idOrClass') to get first instance of element, or...
In HTML pages there are elements and these elements can have event listeners.
Like most universal way I have found to set these is element.addEventListener with first parameter for what and second parameter listener.
Is say like that with "click" universal?
Like could it run on all internet browsers?
Would jQuery be more universal like that?
Is anything really universal like that?
If so please tell me.
I found that getElementById is not universal, it does not support older browsers, but on modern browsers, universal.
X E.
addEventListener should work fine without jquery.
as far as selecting elements... you could just use document.querySelector('idOrClass') to get first instance of element, or document.querySelectorAll('className') to get all elements with given class
 
Solution
I was looking for like comparison with browsers, how far back does jQuery compatability go and how far back does getElementById and addEventListener go?
I know now that they both work in all modern browsers.
I think if either does not work, people nearly may as well be using punch cards and it is okay to report "Please update your browser".
I may be using HTML to limit things and Javascript to allow things so if Javascript does not work I can just ask for a browser update.
X E.
 
I found that jQuery is like just for current browsers so like element.addEventListener is like more reliable.
element.addEventListener works with almost all browsers, excepting internet explorer before 9.
Internet Explorer is deprecated and out of production now so according to like my research, use element.addEventListener.
There is also option of using HTML.
For browser support of getElementById and element.addEventListener, I found these.
These have compatibility near bottom.
Anyway, like my answer is use getElementById and addEventListener as these are supported further back with time and are standard.
Maybe this helps someone other than just me.
X E.
 

New Threads

Buy us a coffee!

Back
Top Bottom