JimE
JimE

Reputation: 27

GetElementsByID() vs QuerySelector()

Researching a solution to the spotty IE support for GetElementsByID() and QuerySelector(), I got to wondering if there is not a process in JS similar to @supports (in CSS) that returns whether a method is supported by the user's browser.

Something like methodExists( "getElementsByClass" ) > true/false.

Probably not, but it would be nice.

Upvotes: -3

Views: 239

Answers (1)

rishichawda
rishichawda

Reputation: 453

First of all, it is getElementById and not GetElementsByID. Secondly, if you want to check support for any method, you can always check in caniuse whether your browser is supported or not.

If you want to check through JS, you can always check if document.methodNameYouWantToCheck or window.methodNameYouWantToCheck ( based on where we can expect the method to be available ) is undefined or not. If it is undefined, then it is not supported.

Let me know if this answers your question or if you had some other query which I probably didn't understand.

Upvotes: 2

Related Questions