How does the browser identify inline JavaScripts?

Johar Ali
Published on 11-Jan-2018 08:08:05
Let’s say the following line we have in our HTML −<input type="Button" value="Result" onclick="alert(‘Hello World!’);"/>Here the browser identifies inline JavaScript by detecting onclick, even when <script> tag wasn’t available.The following are some of the suggestions for using inline JavaScripts −You should consider inline script elements such as <script>...</script>) if the ... Read More

What are the rules for JavaScript's automatic semicolon insertion (ASI)?

Amit Sharma
Published on 11-Jan-2018 07:45:20
JavaScript’s automatic semicolon insertion (ASI) is to insert missing semicolons. The following statements are affected by automatic semicolon insertion −empty statement var statement expression statement do-while statement continue statement break statement return statement  throw statementThe rules are in the following specification −When, as a Script or Module is parsed from ... Read More

Where should jQuery code go in header or footer?

Ali
Ali
Published on 11-Jan-2018 06:30:43
It’s always a good practice to add jQuery code in footer i.e. just before the closing </body> tag. If you have not done that, then use the defer attribute.Use defer attribute so the web browser knows to download your scripts after the HTML downloaded −<script src="new.js" defer="defer"></script>The defer attribute is ... Read More

How to disable resizable property of textarea using JavaScript?

Rahul Sharma
Published on 11-Jan-2018 06:27:06
To disable resizable property, use CSS style −textarea {    resize: none; }To disable specific textarea with different attribute values, try the following. Let’s say the attribute is set to “demo” −textarea[name=demo] {    resize: none; }Let’s say the id attribute is “demo” −<textarea id="demo"></textarea>For the above, #demo {   ... Read More

How to handle when JavaScript is turned off?

Johar Ali
Published on 11-Jan-2018 06:23:54
Nowadays, almost every web browser supports JavaScript. If it is turned off, you can use <noscript> tag. To let users know about non-JavaScript web browsers, use the <noscript> tag. The HTML <noscript> tag is used to handle the browsers, which do recognize <script> tag but do not support scripting. This ... Read More

JavaScript function in href vs. onClick

Amit Sharma
Published on 11-Jan-2018 06:18:15
Both onclick & href have different behaviors when calling JavaScript directly. Also the script in href won’t get executed if the time difference is short. This is for the time between two clicks.ExampleHere’s an example showing the usage of href vs onClick in JavaScript. Live Demo<html>    <head>       ... Read More

What is the difference between global and local Variables in JavaScript?

Swarali Sree
Published on 23-Jan-2018 06:43:40
The scope of a variable is the region of your program in which it is defined. JavaScript variables have only two scopes.Global Variables − A global variable has a global scope which means it can be defined anywhere in your JavaScript code.Local Variables − A local variable will be visible ... Read More

How to declare global Variables in JavaScript?

Ali
Ali
Published on 10-Jan-2018 11:30:50
A global variable has global scope. The scope of a variable is the region of your program in which it is defined. JavaScript variables have only two scopes.Global Variables − A global variable has global scope which means it can be defined anywhere in your JavaScript code.Local Variables − A ... Read More

How to declare variables in JavaScript?

Rahul Sharma
Published on 10-Jan-2018 11:06:47
Like many other programming languages, JavaScript has variables. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container.Before you use a variable in a JavaScript program, you must declare it. Variables are declared with ... Read More

Where should the Google Analytics Tracking Code be placed?

Johar Ali
Published on 10-Jan-2018 10:46:17
When integrating your website with Google Analytics, add the Tracking Code in your code. This will allow Google Analytics to track the page views and provide other analytics.Copy the code and place it just before closing <head> tag i.e. </head> in your website code. When you will integrate, the following ... Read More
Advertisements