0% found this document useful (0 votes)
19 views

External File: Myscript - JS: .Getelementbyid ( ') - Onclick

JavaScript allows you to select and modify HTML elements using functions like getElementById(). External JavaScript files can be used to store code that is needed on multiple pages. Comments are used to explain code and are denoted with double slashes or between /* and */. Identifiers in JavaScript are used to name variables, functions, and labels and must start with a letter, underscore or dollar sign while subsequent characters can include numbers.

Uploaded by

Kira Kira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

External File: Myscript - JS: .Getelementbyid ( ') - Onclick

JavaScript allows you to select and modify HTML elements using functions like getElementById(). External JavaScript files can be used to store code that is needed on multiple pages. Comments are used to explain code and are denoted with double slashes or between /* and */. Identifiers in JavaScript are used to name variables, functions, and labels and must start with a letter, underscore or dollar sign while subsequent characters can include numbers.

Uploaded by

Kira Kira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Script

.getElementById(‘’).

onclick=

document.getElementById('demo').innerHTML = Date()

.innerHTML

.src

.style

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Paragraph changed.";
}
</script>

External file: myScript.js


function myFunction() {
  document.getElementById("demo").innerHTML = "Paragraph changed.";
}

External scripts are practical when the same code is used in many different web
pages.x

<script src="https://www.w3schools.com/js/myScript1.js"></script>

 Writing into an HTML element, using innerHTML.


 Writing into the HTML output using document.write(). [Using
document.write() after an HTML document is loaded, will delete all
existing HTML:]
 Writing into an alert box, using window.alert().
 Writing into the browser console, using console.log().

Semicolons separate JavaScript statements.

var a, b, c;     
a = 5;           
b = 6;           
c = a + b; 
JavaScript uses arithmetic operators ( + - * / ) to compute values

Strings are text, written within double or single quotes:

JavaScript uses an assignment operator ( = ) to assign values to variables:

Code after double slashes // or between /* and */ is treated as a comment.

JavaScript Identifiers
Identifiers are names.

In JavaScript, identifiers are used to name variables (and keywords, and


functions, and labels).

The rules for legal names are much the same in most programming languages.

In JavaScript, the first character must be a letter, or an underscore (_), or a


dollar sign ($).

Subsequent characters may be letters, digits, underscores, or dollar signs.

Hyphens are not allowed in JavaScript. They are reserved for subtractions.

You might also like