Found 9150 Articles for Object Oriented Programming

How to set the length of the item relative to the rest with JavaScript?

Abhinaya
Updated on 23-Jun-2020 12:16:12

120 Views

Use the flex property in JavaScript to set the length of the item relative to the rest. You can try to run the following code to implement flex property with JavaScript −Example                    #box {             border: 1px solid #000000;             width: 300px;             height: 400px;             display: flex;          }                              DIV1          DIV2          DIV3             Set                function display() {             var a = document.getElementById("box");             var b = a.getElementsByTagName("DIV");             var j ;             for (j = 0; j < b.length; j++) {                b[j].style.flex = "1";             }          }          

Which is the best JavaScript compressor?

Nitya Raut
Updated on 23-Jun-2020 12:24:06

224 Views

Here are some of the best JavaScript compressors available −Google Closure CompilerThe Google Closure compiler runs JavaScript quickly and used for a superior JavaScript. It parses your JavaScript, analyzes it, removes dead code, rewrites, and minimizes what's left.JSMinIf you want to minify, then use the JSMin to remove unnecessary comments.YUI CompressorThe YUI Compressor is used to minify the JavaScript files fastly and is secure.

Difference between window.location.href, window.location.replace and window.location.assign in JavaScript?

Arjun Thakur
Updated on 23-Jun-2020 12:14:47

626 Views

The window object includes the location object in JavaScript. It includes the following properties −window.location.hrefIt returns the URL of the current page.Example           Click below to get the complete URL of the page.       URL                function display() {             var res = location.href;             document.write(res);          }           window.location.replaceIt is used to replace the current document.Example           Replace current document                function display() {             location.replace("https://www.qries.com")          }           window.location.assignIf you want to load a new document, use JavaScript assign.Example           Open new document                function display() {             location.assign("https://www.qries.com")          }          

How to add an event handler to an element in JavaScript HTML DOM?

Saurabh Jaiswal
Updated on 22-Aug-2022 08:00:39

2K+ Views

This tutorial will teach how to add an event handler to an element in JavaScript. There are two ways to add an event handler to any element, the first is using the addEventListener method and another is using the event attributes. Using the addEventListener() Method The addEventListener() method is used to attach an event handler to any DOM element. The syntax of this method is following. Syntax element.addEventListener( event, function, capture ) Parameter Event − The name of the event you want to apply on the element e.g. click, mouseover, submit, etc. Function − The callback function which ... Read More

How to add many Event Handlers to the same element with JavaScript HTML DOM?

Saurabh Jaiswal
Updated on 22-Aug-2022 08:12:29

13K+ Views

It is very common to use the events while we are programming in JavaScript. Suppose you are creating a modal that opens up on clicking a button or hovering over using the cursor, here we using two events on a single element but JavaScript does not have any official way to use many event listeners on a single element. In this article, we will learn How to add many Event Handlers to the same element with JavaScript HTML DOM. To achieve this, we have the following approaches given below. Using Multiple addEventListener Methods Using the ES6 Way Using ... Read More

What is the fastest, pure JavaScript, Graph visualization toolkit?

George John
Updated on 30-Jul-2019 22:30:21

133 Views

The fastest and pure JavaScripr Graph visualization toolkit isJavaScript InfoVis Toolkit. With it, you can, Perform Graph manipulation, Create bar graphs, Custom nodes, Implementing NodeTypes Adding subtrees, Drag and drop nodes, etc.

How to create a new img tag with JQuery, with the src and id from a JavaScript object?

Anvi Jain
Updated on 23-Jun-2020 12:06:14

2K+ Views

To create a new img tag in JavaScript, pass an HTML string to the constructor,var myImg = $(''); $(document.createElement(myImg)); myImg.attr('src', responseObject.imgurl);You can also use the following code to create a new img tag with the attributes like src, id, etc −var myImg = $('', {    id: 'id1',    src: exampleimg.png',    alt: 'Alt text' });

How can I escape HTML special chars in JavaScript?

Shubham Vora
Updated on 14-Jul-2022 14:27:51

10K+ Views

HTML contains special characters such as ‘, ’ ‘/, ’ and many more such as single and double commas. These special characters are used for the HTML tag, such as ‘’ is used to close the HTML tag. This tutorial teaches us to escape HTML special characters in JavaScript.Now, the question is that what if we want to use these characters inside the HTML content? If we use special characters normally in the HTML content, it considers it the opening or closing HTML tag and produces an unknown error.For example, we need to render the below string to the browser. ... Read More

Why is isNaN(null) == false in JS?

Disha Verma
Updated on 17-Mar-2025 12:33:08

731 Views

The isNaN() function in JavaScript is used to check whether a given value is NaN. This function converts the argument to a number first, then checks if it's NaN. When you pass null to isNaN(), it returns false, which can be surprising. This happens because of JavaScript type coercion when using isNaN(). In this article, we will understand why isNaN returns false for null. Understanding isNaN and Type Coercion in Js Before moving forward in this article you need to understand the following key concepts of this article: isNaN in Js: The isNaN() function ... Read More

What is the best JavaScript code to create an img element?

Ankith Reddy
Updated on 23-Jun-2020 12:07:26

195 Views

Try any of the following for the width of the image you want to create −myImg.setAttribute('width', '5px');OrmyImg.width = '5';OrmyImg.style.width = '5px';You can also try the following code to add the width and height to the background image −var myImg = new Image(5,5); myImg.src = 'http://www.example.com';

Advertisements