Javascript Articles - Page 550 of 671

The correct way to work with HTML5 checkbox

Giri Raju
Updated on 24-Jun-2020 14:16:39

214 Views

The following is the correct way −ExampleHere is an example −           Checkbox Control                         Maths           Physics            

HTML5 Cross Browser iframe post message - child to parent?

George John
Updated on 24-Jan-2020 11:25:46

207 Views

The parent object provides a reference to the main window from the child.The following is the parent code. The directive below triggers the iFrame to send a message to the parent window every 3 seconds. No initial message from the main window needed!var a= window.addEventListener ? "addEventListener" : "attachEvent";// here a is the event method var b= window[a];// here b is the eventer var c= a== "attachEvent" ? "onmessage" : "message";// here c is the message event // Listen to message from child window b (c, function(e) {    var d= e.message ? "message" : "data";// here d is ... Read More

Is there a way to add/remove several classes in one single instruction with classList in HTML and JavaScript?

Samual Sam
Updated on 24-Jun-2020 14:13:58

216 Views

The classList property returns the class name(s) of an element, as a DOMTokenList object. The classList property is read-only, however, you can modify it by using the add() and remove() methods.The classListproperty ensures that duplicate classes are not unnecessarily added to the element. In order to keep this functionality, if you dislike the longhand versions or jQuery version, I’d suggest adding addMany function and removeMany to DOMTokenListThese would then be useable like so −DOMTokenList.prototype.addMany = function(classes) {    var arr = classes.split(' ');    for (var j = 0, length = arr.length; j < length; j++) {       this.add(array[j]); ... Read More

Upload from local drive to local filesystem in HTML with Filesystem API

vanithasree
Updated on 24-Jun-2020 14:09:06

238 Views

To upload from local drive to the local file system, we can use −Webkitdirectory attribute on − This allows the user to select a directory by the appropriate dialog box.Filesystem API is a sandboxed filesystem, which allows us to store files on client’s machine.File API allows us to read files. Files are accessible by elementAll of the above is working fine in Google Chrome.WebKit directory is a much better option among these. Use the following for directory −webkitRequestFileSystem(    window.TEMPORARY, 5 * 1024 * 1024, function(_fs) {       fs = _fs;    }, ErrAbove, err and fs are −var fs, err = function(err) {    throw err; };

Mouse event not being triggered on HTML5 canvas? How to solve it?

Arjun Thakur
Updated on 24-Jun-2020 14:09:51

518 Views

To trigger mouse event we can add −-webkit-transform: translate3d(0, 0, 0)In addition to this canvas can also be styled.Another way is to add a listener in the event mousemove,canvas.addEventListener("mousemove", this.checkMouseLocation.bind(this, this.inputs), false);By adding this listener, we can easily trigger a mouse move event in HTML5.

Create JS Radial gradient with matrix in HTML

Sreemaha
Updated on 02-Jun-2020 07:40:33

274 Views

JSRadial gradient with matrix is created in the following way. You can try to run the following way to create JS Radial gradient with matrix −var canvas1 = document.getElementById("canvas"); //canvas1 variable to identify given canvas var ctx1 = canvas.getContext("2d"); //This is used to tell context is 2D   var gradient1 = ctx1.createRadialGradient(100/horizontalScale, 100/verticalScale, 100, 100/horizontalScale, 100/verticalScale, 0); //This will create gradient with given canvas context   gradient1.addColorStop(1, "green"); //New color green is added to gradient gradient1.addColorStop(0, "red"); //New color red is added to gradient ctx1.scale(horizontalScale, verticalScale); //Context matrix ctx1 is shrinked according to horizaontal and vertical scale ... Read More

How to change date time format in HTML5?

karthikeya Boyini
Updated on 24-Jun-2020 13:53:24

3K+ Views

The date-time format can be changed by using custom HTML5 elements. If we wish to change or override existing Html tags then we can do so with the help of shadow DOM.We can make customizable tags like −Here is an example −However, E10 and older versions do not support customizable tags; however, all newer versions support customizable tags.

HTML5/CSS align list-items depending on other columns mutual height

varma
Updated on 24-Jun-2020 13:54:45

217 Views

Align list-item with the help of flex. Flex will make columns flexible according to content. The wrapper will layout columns in a row..wrap{    display : flex }// This will help wrapper to become flexible .wrap.col{    flex: 1 0 33%; }Flex is basically a property which helps in making element flexible.Use the following to keep the lists vertically aligned to the bottom −.col .content {    margin-top: auto; }

How to save DIV as Image with HTM5 canvas to image with the extension?

Samual Sam
Updated on 24-Jun-2020 13:57:04

6K+ Views

DIV content can be saved as an image with the help of html2canvas() function in JavaScript. DIV tag defines a section in HTML document.Example      Welcome This shows the division area named cpimg.The html2canvas() function save div as an image with the following code −html2canvas(document.querySelector(“#cpimg”)).then(canvas  {         document.body.appendChild(canvas)  });It saves the referred div section “cpimg” into the image.

How to save canvas data to file in HTML5?

George John
Updated on 24-Jun-2020 13:55:49

2K+ Views

A Canvas is just a rectangular area on the HTML page. We can draw graphics in this rectangular area (Canvas) with the help of JavaScript. Canvas can be created in HTML5 as −                                 This creates an empty canvas with name canvas1 with width=200 and height=100. To draw graphics in it, we use JavaScript −var canvas = document.getElementById("Canvas1");  var ctx1 = canvas.getContext("2d"); ctx1.moveTo(0, 0); ctx1.lineTo(300, 200);  ctx1.stroke(); // This method actually draw graphics as per context object             To save this graphic, we need ... Read More

Advertisements