Found 8591 Articles for Front End Technology

How to set the color of the rule between columns with JavaScript?

Shubham Vora
Updated on 09-Nov-2022 11:23:35

205 Views

In this tutorial, we will learn how to set the color of the rule between columns with JavaScript. Multiple columns are used to increase the readability of long paragraphs or articles. The column-count CSS property is used to divide the text into some columns. To set the color of the rule between columns with JavaScript, we used the columnRuleColor property of the style object, which is in the element object of an HTML element. Using the style.columnRuleColor Property In JavaScript, the style.columnRuleColor property of an element is used to set the color of the rule between columns of an element. ... Read More

How to work with Structs in JavaScript?

Shubham Vora
Updated on 15-Nov-2022 09:06:39

8K+ Views

In this tutorial, let us discuss how to work with structs in JavaScript. What is a struct? A struct is the short name of the data structure. The structure creates multiple values of different types in a single variable. We can use a struct to generate records. A struct in JavaScript is the object creation. Other than that, JavaScript does not have a struct feature. Let us see the methods to create a structure. Using the String split() Method Let us learn to create a struct using string split. Separate a string with a comma and whitespace and give it ... Read More

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

739 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';

How to create JavaScript regexes using string variables?

Abhinaya
Updated on 23-Jun-2020 12:07:53

154 Views

Yes, use new RegExp(pattern, flags) to achieve this in JavaScript.You can try to run the following code to implement JavaScript regex using string variables −                    var str = 'HelloWorld'.replace( new RegExp('hello', 'i'), '' );          document.write(str);          

Is their JavaScript “not in” operator for checking object properties?

Vrundesha Joshi
Updated on 23-Jun-2020 11:59:16

2K+ Views

To get only the else part, just negate, using ! the operator in JavaScript. You can try to run the following code to achieve this −var arr = {}; if (!(id in arr)) { } else { }In addition, if you want the existence of a property in an object, then use hasOwnProperty −if (!arr.hasOwnProperty(id)) { } else { }

Create a syntax highlighting code with JavaScript.

Srinivas Gorla
Updated on 23-Jun-2020 12:00:35

193 Views

To create a syntax-highlighting code with JavaScript, use the prettify library. Add the following in your code to add the library for syntax highlighting −To use it, add the following to your tag −    Code comes here

How to create a JavaScript code for multiple keys pressed at once?

Arjun Thakur
Updated on 23-Jun-2020 11:59:51

658 Views

Use the keydown event in JavaScript to get to know which keys are pressed at once. The following is the script −Examplevar log = $('#log')[0],    keyPressed = []; $(document.body).keydown(function (evt) {    var li = keyPressed [evt.keyCode];    if (!li) {       li = log.appendChild(document.createElement('li'));       keyPressed [evt.keyCode] = li;    }    $(li).text(Key Down: ' + evt.keyCode);    $(li).removeClass('key-up'); }); $(document.body).keyup(function (evt) {    var li = keyPressed [evt.keyCode];    if (!li) {       li = log.appendChild(document.createElement('li'));    }    $(li).text('Key Up: ' + evt.keyCode);    $(li).addClass('key-up'); });

Advertisements