Javascript Articles

Page 355 of 534

World Map on HTML5 Canvas or SVG

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 864 Views

Creating interactive world maps in web browsers can be accomplished using SVG with libraries like Raphael.js or using HTML5 Canvas. This tutorial demonstrates both approaches for rendering world maps. Using SVG with Raphael.js Raphael.js is a JavaScript library that simplifies working with vector graphics in web browsers. Here's how to get started: // Create Raphael paper (canvas) var paper = Raphael("world-map", 800, 400); // Drawing basic shapes for map elements var circle = paper.circle(50, 40, 10); circle.attr("fill", "#f00"); circle.attr("stroke", "#fff"); // Create a simple country shape using path var country ...

Read More

Assign new value to item in an array if it matches another item without looping in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 156 Views

In JavaScript, you can assign a new value to an array item that matches a condition without using traditional loops. This can be achieved using array methods like filter() combined with map(), or more efficiently with forEach() or find(). Using filter() and map() The filter() method finds matching items, and map() modifies them. Here's how to change "Bob" to "Carol" in an array of objects: const studentDetails = [ {Name: "John"}, {Name: "David"}, {Name: "Bob"}, {Name: "Mike"} ]; var ...

Read More

Which browsers support the HTML5 History API?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 267 Views

The HTML5 History API allows web applications to manipulate browser history programmatically, enabling single-page applications to update URLs without full page reloads. Understanding browser support is crucial for implementing this feature effectively. Browser Support Overview The HTML5 History API is now widely supported across modern browsers. WebKit-based browsers and Firefox 4 were among the first to implement this feature, but support has expanded significantly since then. Supported Browsers Firefox: Version 4 and above Google Chrome: All versions (since Chrome 5) Internet Explorer: Version ...

Read More

Copy objects with Object.assign() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 229 Views

The Object.assign() method is used to copy one or more source objects to a target object. It invokes getters and setters since it uses both 'get' on the source and 'set' on the target. Syntax Object.assign(target, ...sourceObjects); The first parameter is the target object that will be modified and returned. The remaining parameters are source objects whose properties will be copied to the target. Basic Example const target = { a: 1, b: 2 }; const source = { b: 3, c: 4 }; const result = Object.assign(target, source); console.log("Target ...

Read More

How to save HTML5 canvas data to file?

George John
George John
Updated on 15-Mar-2026 617 Views

HTML5 canvas provides several methods to save canvas data to files. The approach depends on whether you're working in a browser or Node.js environment. Method 1: Browser Environment - Download as File In browsers, use toDataURL() or toBlob() to convert canvas data and trigger a download: Canvas Save Example Save Canvas // Draw something on canvas ...

Read More

How to get a key/value data set from a HTML form?

Nishtha Thakur
Nishtha Thakur
Updated on 15-Mar-2026 1K+ Views

To get key/value data from an HTML form, you can use several approaches including jQuery's serializeArray(), vanilla JavaScript with FormData, or manual field extraction. HTML Form Example Let's start with a sample HTML form: Using jQuery serializeArray() jQuery's serializeArray() returns an array of objects with name and value properties: // Using jQuery serializeArray() var data = $('#form1').serializeArray(); console.log(data); // Convert ...

Read More

How to display only the current year in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 517 Views

To display only the current year in JavaScript, use the getFullYear() method with the Date object. This method returns a four-digit year as a number. Syntax new Date().getFullYear() Example: Display Current Year in HTML Current Year Display The Current Year: document.getElementById("currentYear").innerHTML = new Date().getFullYear(); ...

Read More

How to either determine SVG text box width or force line breaks after 'x' characters?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 313 Views

When working with SVG text elements, you often need to control text wrapping since SVG doesn't automatically wrap text like HTML. This tutorial shows how to measure text width using getBBox() and implement word wrapping. The Problem SVG text elements don't wrap automatically. Long text will extend beyond boundaries, requiring manual line breaks based on width measurements. Using getBBox() for Text Measurement The getBBox() method returns the bounding box dimensions of SVG elements, including text width and height. ...

Read More

How to "enable" HTML5 elements in IE 8 that were inserted by AJAX call?

George John
George John
Updated on 15-Mar-2026 354 Views

To enable HTML5 elements in IE 8 that were inserted by AJAX calls, you need to use plugins like html5shiv and manually create elements using document.createElement. The HTML5 Shiv enables use of HTML5 sectioning elements in legacy Internet Explorer and provides basic HTML5 styling for Internet Explorer 6-9. The Problem IE 8 doesn't recognize HTML5 elements like , , or . When these elements are inserted via AJAX, they won't render properly even with html5shiv loaded. Solution: Manual Element Creation You need to call document.createElement for each HTML5 element before inserting AJAX content: ...

Read More

Demonstrate nested loops with return statements in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 683 Views

In JavaScript, you can use return statements inside nested loops to exit from functions early. When a return statement is executed inside nested loops, it immediately exits the entire function, not just the current loop. Example let demoForLoop = () => { for(var outer = 1; outer < 100; outer++){ for(var inner = 1; inner { for(let i = 1; i

Read More
Showing 3541–3550 of 5,340 articles
« Prev 1 353 354 355 356 357 534 Next »
Advertisements