Found 444 Articles for Programming Scripts

How to get the value of the target attribute of a link in JavaScript?

Shubham Vora
Updated on 15-Sep-2022 11:48:20

7K+ Views

In this tutorial, we will learn how to get the value of the target attribute of a link in JavaScript. The target attribute specifies where to open the linked document or page. By default, its value is set to ‘_self, ’ which means the linked document should open in the same window or tab. It can also have values like ‘_blank, ’ ‘_self, ’ ‘_parent, ’ ‘_top, ’ and ‘frame_name’, where each value defines a different location to open the linked document. Using the target property To get the value of the target attribute of a link in JavaScript, use ... Read More

How to improve the performance of JavaScript?

Shubham Vora
Updated on 15-Sep-2022 12:13:02

363 Views

In today's world, almost every website uses JavaScript. Web applications are becoming more complex and more user-interactive, and this has caused performance issues. It results in a poor user experience, which is not desirable for any web application. Different factors cause poor performance, long loading times, and long response times. In this tutorial, we will discuss all of these factors and how to resolve this issue and improve the performance of JavaScript. Light and Compact Code The first thing to improve the performance of JavaScript is to write light and compact code. The JavaScript code can have multiple modules and ... Read More

What will happen if a semicolon is misplaced in JavaScript?

Srinivas Gorla
Updated on 20-May-2020 09:04:03

191 Views

If a semicolon is misplaced in JavaScript, then it may lead to misleading results. Let’s see an example, wherein the if statement condition is false, but due to misplaced semi-colon, the value gets printed.Example                    var val1 = 10;          if (val1 == 15) {             document.write("Prints due to misplaced semi-colon: "+val1);          }          var val2 = 10;          if (val2 == 15) {             // this won't get printed             document.write(val2);          }          

Is it a good practice to place all declarations at the top in JavaScript?

Ayyan
Updated on 20-May-2020 09:07:11

113 Views

Yes, it is a good practice to place all the JavaScript declarations at the top. Let’s see an example −Example           JavaScript String match() Method                        // all the variables declared at top          var str, re, found;                    str = "For more information, see Chapter 3.4.5.1";          re = /(chapter \d+(\.\d)*)/i;          found = str.match( re );          document.write(found );           The following are the valid reasons −Gives a single place to check for all the variables.Helps in avoiding global variablesRe-declarations are avoided.The code is easy to read for others as well.

How to match a regular expression against a string?

Nancy Den
Updated on 23-Jun-2020 08:51:16

311 Views

Use the match() method to match a regular expression against a string in JavaScript. You can try to run the following code to match a regular expression −The following is the parameter −match( param ) − A regular expression object.ExampleYou can try to run the following code to match a regular expression against a string −           JavaScript String match() Method                        var str = "For more information, see Chapter 3.4.5.1";          var re = /(chapter \d+(\.\d)*)/i;          var found = str.match( re );                    document.write(found );          

How to search the value of the href attribute of a link in JavaScript?

Vikyath Ram
Updated on 18-Nov-2023 03:22:23

2K+ Views

To get the value of the href attribute of a link in JavaScript, use the href property. It gives you the URL of the linked document in JavaScript.ExampleYou can try to run the following code to get the value of the href attribute of a link.           Qries                var myLink = document.getElementById("anchorid").href;          document.write("Link: "+myLink);          

How to display the selected option in a dropdown list with JavaScript?

Shubham Vora
Updated on 12-Sep-2023 03:02:04

33K+ Views

In this tutorial, we will learn how to display the selected option in a dropdown list with JavaScript. What is a dropdown list? A dropdown list is a switchable menu that enables users to select one item from various options. A drop-down list is generated with the tag is most frequently used in forms to gather user input. After submitting the form, the name attribute must refer to the form's data. The DOM API functions getElementById() and querySelector() can be used to choose a element. The process use the querySelector() function to first select the "button" and "select" ... Read More

How to show all the options from a dropdown list with JavaScript?

Sharon Christine
Updated on 20-May-2020 08:56:35

5K+ Views

To show all the options from a dropdown list, use the options property. The property allows you to get all the options with length property.ExampleYou can try to run the following code to get all the options from a drop-down list.Live Demo                                 One             Two             Three                                 Click the button to get all the options                function display() {             var a, i, options;             a = document.getElementById("selectNow");             options = "";             for (i = 0; i < a.length; i++) {                options = options + " " + a.options[i].text;             }             document.write("DropDown Options: "+options);          }          

How to convert String to Boolean in JavaScript?

Fendadis John
Updated on 20-May-2020 08:55:35

266 Views

You can try to run the following to learn how to convert String to Boolean in JavaScript.ExampleLive Demo           Convert String to Boolean                var myString = "Amit";          document.write("Boolean : " + Boolean(myString));          

How to return a number indicating the Unicode value of the character?

Alankritha Ammu
Updated on 23-Jun-2020 08:41:29

353 Views

The charCodeAt() method returns a number indicating the Unicode value of the character at the given index. Unicode code points range from 0 to 1, 114, 111. The first 128 Unicode code points are a direct match of the ASCII character encoding.The following parameter is supported by charCodeAt(index) −index − An integer between 0 and 1 less than the length of the string; if unspecified, defaults to 0.ExampleYou can try to run the following code to return a number indicating the Unicode value of the character −           JavaScript String charCodeAt() Method           ... Read More

Advertisements