Javascript Articles

Found 5,338 articles

Facing Problem in retrieving HTML5 video duration

Chandu yadav
Chandu yadav
Updated on 12-Mar-2026 503 Views

A common problem when working with HTML5 video is that the duration property returns NaN (Not a Number) when you try to access it before the browser has finished loading the video's metadata. This happens because the video file's metadata (which contains the duration, dimensions, etc.) is not available immediately after the page loads. Why Does video.duration Return NaN? The HTML5 element has a readyState attribute that indicates how much data the browser has loaded. It has values from 0 to 4 − 0 (HAVE_NOTHING) − No data available yet. 1 (HAVE_METADATA) − Metadata (duration, dimensions) is loaded. ...

Read More

What is the usage of the cross-origin attribute in HTML5?

Arjun Thakur
Arjun Thakur
Updated on 12-Mar-2026 362 Views

The crossorigin attribute in HTML5 is a CORS (Cross-Origin Resource Sharing) settings attribute. It controls how the browser handles cross-origin requests when loading resources like images, scripts, and stylesheets from third-party domains.As the official specification states − The crossorigin attribute is a CORS settings attribute. Its purpose is to allow images from third-party sites that allow cross-origin access to be used with canvas. Why Is the crossorigin Attribute Needed?By default, when you load an image from a foreign origin and draw it onto an HTML5 , the canvas becomes tainted. A tainted canvas cannot be read back using methods like ...

Read More

Remember and Repopulate File Input in HTML5

Nancy Den
Nancy Den
Updated on 12-Mar-2026 385 Views

Browsers do not allow you to programmatically set the value of a file for security reasons. This means you cannot "remember" a previously selected file and repopulate the input on page reload using JavaScript alone. However, HTML5 introduced the Drag and Drop API along with the DataTransfer object, which provides a workaround − users can drag files onto a drop zone, and your code can process those files just like a file input would. How Drag and Drop Works with Files When a user drops a file onto a designated area, the browser fires a drop event. The dropped ...

Read More

Are new HTML5 elements like <section> and <article> useless?

Chandu yadav
Chandu yadav
Updated on 12-Mar-2026 186 Views

No, HTML5 semantic elements like and are not useless. They are extremely useful for screen readers and assistive technologies, helping visually impaired users navigate and understand the structure of your web page. They are also beneficial for eBook readers, search engines, and any tool that parses HTML for meaning. While you could use generic tags for everything, semantic elements convey the purpose of the content to both browsers and developers, making your code more readable and accessible. The Element The element represents a thematic grouping of content, typically with a heading. Use it to divide ...

Read More

HTML5 Canvas to PNG File

Daniol Thomas
Daniol Thomas
Updated on 12-Mar-2026 939 Views

To convert an HTML5 Canvas to a PNG file, you use the canvas.toDataURL() method. This method generates a base64-encoded data URL representing the canvas content as a PNG image. You can then use this data URL to display the image or trigger a file download. How canvas.toDataURL() Works The toDataURL() method returns a string containing the canvas image in the specified format. For PNG, the returned string looks like this − data:image/png;base64, iVBORw0KGgoAAAANSUhEUg.... You can assign this data URL to an tag's src attribute to display the canvas content as a regular image − ...

Read More

How to Title Case a sentence in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 11-Mar-2026 10K+ Views

Title Case a sentence in javascriptIt is nothing but converting first element of all the words in a sentence in to uppercase while the other elements remain in lowercase. The provided string(sentence) may contains a bunch of lowercase and uppercase elements. So we need an algorithm to Title Case the provided string.AlgorithmDivide all the words in the sentence individually. This task can be achieved by using string.split() method.Convert all the elements in each and every word in to lowercase using string.toLowerCase() method. Loop through first elements of all the words using for loop and convert them in to uppercase. After converting, ...

Read More

Explain about logical not(!) operator in detail with example in javascript?

vineeth.mariserla
vineeth.mariserla
Updated on 11-Mar-2026 192 Views

NOT operatorThe logical NOT operator gives true for false values and false for true values. var x = 200; var y = 300; document.getElementById("logical").innerHTML = !(x < y) + "" + !(x > y); Outputfalse true

Read More

How to display output in javascript?

vineeth.mariserla
vineeth.mariserla
Updated on 11-Mar-2026 3K+ Views

There are 4 ways to display the output in JavaScript. a) Displaying the output in HTML elements, using innerHTML attribute.  alert(2 + 3); In alert window box, the output5In case of handling json strings, or some other big data console.log is the best choice.

Read More

Write a number array and add only odd numbers?

vineeth.mariserla
vineeth.mariserla
Updated on 11-Mar-2026 1K+ Views

Odd number summation using JavaScript. var tot = 0; var a = [1,45,78,9,78,40,67,76]; for(var i = 0; i

Read More

What are the types of tags involved in javascript?

vineeth.mariserla
vineeth.mariserla
Updated on 11-Mar-2026 1K+ Views

Html taga) The tag is used to define a client-side script.b) The tag  contains scripting statements or an external script file.JavaScript code must be keep in script tag.Let's see the use of the tag. For suppose declare the variable outside the script tag.    var a = 1;    var b = 2;    var c = a + b; document.getElementById("tag").innerHTML = c; Output3

Read More
Showing 1–10 of 5,338 articles
« Prev 1 2 3 4 5 534 Next »
Advertisements