AmitDiwan has Published 10744 Articles

Hide a video tag on a web page - JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 08:18:01

4K+ Views

Let’s say we have the following sample video tag on a web page        You cannot play video here...... To hide a video on a web page, use yourVariableName.style.display=’none’.ExampleFollowing is the code −            Document   ... Read More

Implement Bubble sort with negative and positive numbers – JavaScript?

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 08:13:49

904 Views

Let’s say the following is our unsorted array with negative and positive numbers −var arr = [10, -22, 54, 3, 4, 45, 6];ExampleFollowing is the code to implement Bubble Sort −function bubbleSort(numberArray, size) {    for (var lastIndex = size - 1; lastIndex > 0; lastIndex--) {       ... Read More

What happens when length of object is set to 0 - JavaScript?

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 08:07:12

351 Views

Let’s say the following is our array object −var arrayObject =    [       "John",       "David",       "Mike"    ]You can use length property to set the length to 0 and clear memoryThe syntax is as follows to clear memory −yourArrayObjectName.length=0; // To ... Read More

How to make a condition for event 'click' inside/outside for multiple divs - JavaScript?

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 08:02:07

1K+ Views

You can use event listeners for clicks.ExampleFollowing is the code − Live Demo            Document           First Division               Second Division      document.addEventListener('click', callEventFuncion)   ... Read More

How to concatenate the string value length -1 in JavaScript.

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 07:54:56

302 Views

For this, use join(). It will concatenate the string value length-1.ExampleFollowing is the code −var count = 5; var values = new Array(count + 1).join('John'); console.log(values); var count1 = 5; var values1 = new Array(count1).join('John'); console.log(values1);To run the above program, you need to use the following command −node fileName.js. Here, ... Read More

Using JSON.stringify() to display spread operator result?

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 07:46:10

1K+ Views

With Spread Operator, allow the expression to expand to multiple arguments, elements, variables, etc.You can use JSON.stringify() to convert the JavaScript object to string. Here, we have our object as the result of using spread operator on details1 and details2.ExampleFollowing is the code −var details1 = { name: 'John', age: ... Read More

Validate Tutorialspoint URL via JavaScript regex?

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 07:31:44

205 Views

To validate a specific URL, use regular expression.ExampleThe code is as follows −function validateSoundURL(myURL) {    var regularExpression = /^https?:\/\/(tutorialspoint\.com)\/(.*)$/;    return myURL.match(regularExpression) && myURL.match(regularExpression)[2] } console.log(validateSoundURL("https://tutorialspoint.com/index")); console.log(validateSoundURL("https://tutorialspoint.com/java"));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo259.js.OutputThis will produce the following output on ... Read More

Set a fixed element and scroll another - jQuery

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 07:30:18

2K+ Views

Let’s say the following is our fixed element div −    Fixed The CSS style to fix the above element −.fixedElement {    position: fixed;    background-color: skyblue;    top: 0;    left: 0;    right: 0; }Following is our element, which will be scrolled −    David Miller Now, ... Read More

Access the file contents from inside the callback function and display on console – jQuery

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 07:24:35

667 Views

Let’s say the following is our file and we need to read this file using jQuery.The name of the file details −ExampleFollowing is the code − Live Demo            Document        function chooseFile() {     ... Read More

Output only the first word from select list value - jQuery?

AmitDiwan

AmitDiwan

Updated on 09-Nov-2020 06:58:31

984 Views

Let’s say the following is our select −    Get First Name    Get First Name Only To get only the first word, use split() on the basis of space and can select the 0th index value.ExampleFollowing is the code − Live Demo            Document ... Read More

Advertisements