0

Suppose I have an variable assign to an "video" tag, how can I check if this variable is refer to the object of "HTMLVideoElement"

var video = document.getElementById('video')
if (video != object HTMLUnknownElement) {
//some code here
}

What is the code to replace with object HTMLUnknownElement above?

Thanks

1 Answer 1

1

typeof is pretty useless, it'll just tell you that it's an object. You'd do better with instanceof: video instanceof HTMLVideoElement.

EDIT: Some browsers don't know what an HTMLVideoElement is, so to protect against them throwing an exception here you should check for it: typeof HTMLVideoElement !== "undefined" && video instanceof HTMLVideoElement.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.