4.27. Introduction to HTML: basic structure, tags and attributes: Functions in JavaScript

Página 31

4.27. Introduction to HTML: Basic structure, tags and attributes: Functions in JavaScript

Introduction to HTML: Basic structure, tags and attributes

HTML, which stands for HyperText Markup Language, is the standard markup language for creating web pages and applications. Along with CSS and JavaScript, HTML is a fundamental technology used to create web content.

Basic structure of an HTML document

An HTML document has a tree structure. The root element is always the html element. Inside the html element, we have two child elements: the head and the body. The head element contains metadata about the document, such as its title and links to its scripts and CSS stylesheets. The body element contains the actual content of the document, such as text, images, videos, etc.

<!DOCTYPE html>
<html>
  <head>
    <title>Page title</title>
  </head>
  <body>
    Page content
  </body>
</html>

HTML tags and attributes

HTML elements are defined using tags. A tag is made up of the name of the element, surrounded by lower and upper characters. For example, <html>, <body>, <head>, <title>, etc.

Some HTML elements can also have attributes. Attributes provide additional information about the element. They are always specified at the beginning of the element tag and consist of a name and a value. For example, the a element, which is used to create links, has an href attribute that specifies the URL of the link.

<a href="https://www.example.com">This is a link</a>

Functions in JavaScript

JavaScript is a programming language that allows you to implement complex functions on web pages. When a web page is more than just static text and images, but interacts with the user, JavaScript is likely involved.

Functions are one of the fundamental building blocks in JavaScript. A function is a JavaScript procedure - a set of instructions that performs a task or calculates a value. To use a function, you must define it somewhere in the scope of where you want to call it.

Defining functions

A function in JavaScript is similar to a procedure - a set of instructions that performs a task or calculates a value, but for a function to be useful, it must be defined. The JavaScript function definition consists of a function keyword, followed by a name, a list of parameters enclosed in parentheses (brackets), and a declaration containing the code to be executed.

function functionname(parameter1, parameter2, parameter3) {
  // code to be executed
}

Calling functions

Once you define a function, you can execute it by calling it from another part of your code. To do this, you use the function name followed by parentheses and provide the values ​​(known as arguments) for the function's parameters.

FunctionName(value1, value2, value3);

We hope this basic information about HTML and JavaScript provides a solid foundation for you to continue learning and exploring these programming languages. Remember, practice is the key to becoming proficient, so keep practicing and building!

Now answer the exercise about the content:

What is the function of attributes in HTML elements?

You are right! Congratulations, now go to the next page

You missed! Try again.

Next page of the Free Ebook:

324.28. Introduction to HTML: basic structure, tags and attributes: Objects and arrays

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or App Store!

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text