Can someone clarify the difference between a constructor function and a factory function in Javascript. When to use one instead of the other? Answer The basic difference is that a constructor function is used with the new keyword (which causes JavaScript to automatically create a new object, set this within t…
Tag: javascript
Event listener for html5 details node state change
I am trying to add an event listener to detect a change in the state of an HTML5 details node. Initially I tried attaching a listener to the open and close events as it makes logical sense to me for a details node to have those listeners, but it doesn’t and I do not see any mention of them in
How to play only the audio of a Youtube video using HTML 5?
Is it possible to play only the audio from a YouTube video using HTML 5 and Javascript? Answer Embed the video player and use CSS to hide the video. If you do it properly you may even be able to hide only the video and not the controls below it. However, I’d recommend against it, because it will be a
Chrome extension: Get last used tab
I’m trying to create a simple plugin for Google Chrome. One of the functions would be a return to the last used tab, but I don’t know how to do it. So, is there any way to get the last used tab? Answer You could try adding a hook into the onSelected event of the tabs and just saving that
JavaScript code to stop form submission
One way to stop form submission is to return false from your JavaScript function. When the submit button is clicked, a validation function is called. I have a case in form validation. If that condition is met I call a function named returnToPreviousPage(); I am using JavaScript and Dojo Toolkit. Rather going …
Regular Expression | Leap Years and More
I’ve recently been looking for a regular expression to do some client side date checking, and I haven’t been able to find one that can satisfy the following criteria: Has a range from 1800 – Now Performs proper date checking with leap years MM/DD/YYYY Form Invalid Date Checking (These constr…
How to highlight text using javascript
Can someone help me with a javascript function that can highlight text on a web page. And the requirement is to – highlight only once, not like highlight all occurrences of the text as we do in case of search. Answer You can use the jquery highlight effect. But if you are interested in raw javascript co…
How to get start and end of day in Javascript?
How to get start ( 00:00:00 ) and end ( 23:59:59 ) of today in timestamp ( GMT )? Computer use a local time. Answer If you need to get the UTC time from those, you can use UTC().
How to create a function that converts a Number to a Bijective Hexavigesimal?
Maybe i am just not that good enough in math, but I am having a problem in converting a number into pure alphabetical Bijective Hexavigesimal just like how Microsoft Excel/OpenOffice Calc do it. Here is a version of my code but did not give me the output i needed: var toHexvg = function(a){ var x=”; var…
Detect if HTML5 Video element is playing [duplicate]
This question already has answers here: How to tell if a <video> element is currently playing? (7 answers) Closed 1 year ago. I’ve looked through a couple of questions to find out if an HTML5 element is playing, but can’t find the answer. I’ve looked at the W3 documentation and it has …