Found 2416 Articles for HTML

HTML DOM createTextNode() Method

AmitDiwan
Updated on 08-Aug-2019 13:36:49

251 Views

The HTML DOM createTextNode() method is used to create a Text Node with the specified text.ExampleLet us look at an example for the createTextNode() method − createTextNode() example Click the below button to create a p element with some text. CREATE    function createText() {       var x = document.createElement("P");       var p = document.createTextNode("This is a sample paragraph created with       createTextNode()");       x.appendChild(p);       document.body.appendChild(x);    } OutputThis will produce the following output −On clicking the CREATE button −In the above example −We ... Read More

HTML DOM createEvent() method

AmitDiwan
Updated on 20-Feb-2021 05:41:11

199 Views

The HTML DOM createEvent() method is used for creating an event object whose type will be specified in the parameter. The event created must be initialized before using it. To dispatch the event to an HTML element you have to use the dispatchEvent() method on that specified node.SyntaxFollowing is the syntax for the HTML DOM createEvent() method −document.createEvent( eventType )Here, the eventType of type string type is a required parameter. The type of events are listed as: AnimationEvent, ClipboardEvent, DragEvent, FocusEvent, HashChangeEvent, InputEvent, KeyboardEvent, MouseEvent, PageTransitionEvent, PopStateEvent, ProgressEvent, StorageEvent, TouchEvent, TransitionEvent, UiEvent, WheelEvent.ExampleLet us look at an example for the ... Read More

HTML DOM createElement() method

AmitDiwan
Updated on 20-Feb-2021 05:42:40

772 Views

The HTML DOM createElement() method is used for creating an HTML element dynamically using JavaScript. It takes the element name as the parameter and creates that element node. You need to use the appendChild() method to have the newly created element as part of DOM .SyntaxFollowing is the syntax for createElement() method −document.createElement(nodename)ExampleLet us look at an example for the createElement() method −Live Demo createElement() example Click the below button to create more buttons CREATE    var i=0;    function createButton() {       i++;       var btn = document.createElement("BUTTON");       ... Read More

HTML DOM createDocumentFragment() method

AmitDiwan
Updated on 20-Feb-2021 05:44:29

115 Views

The HTML DOM createDocumentFragment() method is used for creating a document fragment. The document fragment doesn’t affect the DOM structure as it resides in memory. When we append the document fragment to the DOM, it is basically replaced by its children i.e there is no document fragment appended to the document only its children gets appended.SyntaxFollowing is the syntax for the createDocumentFragment() method −document.createDocumentFragment()It returns a DocumentFragment object, representing the documentFragment node.ExampleLet us look at an example for the HTML DOM createDocumentFragment() method −Live Demo createDocumentFragment() example Click the below button to change list items using the createDocumentFragment ... Read More

HTML DOM createComment() method

AmitDiwan
Updated on 08-Aug-2019 13:08:34

205 Views

The HTML DOM createComment() method is used for creating a comment node with the given text. It takes the comment to be created as a parameter. Since comments are not visible you have to inspect the HTML document after executing this method to see the comment created.SyntaxFollowing is the syntax for the createComment() method −document.createComment( text );Here, text is of type string containing the data that has to be added to the comment.ExampleLet us look at an example for the createComment() method − Click on below button to create and add a comment to this HTML document. COMMENT ... Read More

HTML DOM createAttribute() method

AmitDiwan
Updated on 13-Aug-2019 08:51:25

179 Views

The HTML DOM createAttribute() method is used for creating a specific attribute using JavaScript for an HTML element. The createAttribute() method creates an attribute with the given name and returns the attribute as an Attr object.SyntaxFollowing is the syntax for createAttribute() method −document.createAttribute(attributename)ExampleLet us look at an example for the HTML DOM createAttribute() method − CREATE ATTRIBUTE    #DIV1{       margin-top:15px;       width:250px;       height:200px;       border:2px solid blue;       background-color:lightgreen;    } Click the button to create a "class" attribute for the div ... Read More

HTML DOM cookie property

AmitDiwan
Updated on 13-Aug-2019 08:48:41

209 Views

The HTML DOM cookie property is used for creating, reading and deleting cookies.The cookies are used by website to keep track of user specific information . This method has return type of string containing semi-colon separated list of all the cookies. The cookies are in the key=value pairs format. Cookies are deleted as soon as the browser is closed but you can specify an expiry date for it.SyntaxFollowing is the syntax for −Setting the cookie property −document.cookie = newCookieHere, the newCookie is of type string and is a semicolon separated list of name-value pair. Following are optional values for newCookie.Parameter ... Read More

HTML DOM contains() Method

AmitDiwan
Updated on 22-Nov-2023 04:42:39

908 Views

The HTML DOM contains() method is used to find whether a node is the descendant of the specified node. A descendant can be an immediate child of the node, grandchild and even great-grandchild. It returns a boolean true indicating the node is indeed the descendant of the specified node and false if it isn’t the descendent of the given node. Syntax Following is the syntax for the HTML DOM contains() method − node.contains(givenNode) Here, the givenNode is a mandatory parameter value that specifies if the givenNode is being contained by the node. Example Let us look at an example for ... Read More

HTML DOM console.warn() Method

AmitDiwan
Updated on 08-Aug-2019 12:45:57

129 Views

The HTML DOM console.warn() method is used to display a warning message in the console. In some browsers there is a small exclamation mark in console log for these warnings The console.warn() method will not interrupt your code execution. Developers can use the console.warn() method to give warnings to the user about some user action.SyntaxFollowing is the syntax for console.warn() method −console.warn(message)Here, the message is a mandatory parameter of type string or object. It is displayed as a warning in the console view.ExampleLet us look at an example for the console.warn() method − console.warn() Method Click the below ... Read More

HTML DOM console.trace() Method

AmitDiwan
Updated on 01-Jul-2020 08:14:34

184 Views

The HTML DOM console.trace() method is used to display the stack trace upto the point the console.trace() method has been called upon. It is basically used for displaying the code path i.e how the code ended up at that point.SyntaxFollowing is the syntax for console.trace() method.console.trace(label);Here, label is an optional parameter of type string to specify the label for the code trace. This helps if there are multiple traces for different pieces of code.ExampleLet us look at an example for the console.trace() method − console.trace() Method Click the below button… Start Trace    function Function1(){   ... Read More

Advertisements