function & attributes in HTML | AsgarTech

Function in HTML | AsgarTech


HTML (Hypertext Markup Language) is primarily used for creating the structure and content of web pages. While HTML itself does not have a traditional programming language, it does support the use of functions through the use of attributes.


Some common HTML functions are:


onclick: This function is used to trigger a script or action when an element is clicked. It can be used with various elements such as buttons, links, and images.

Example: <button onclick="myFunction()">Click me</button>


onchange: This function is used to trigger a script or action when the value of an input element changes. It can be used with input types such as text, select, and checkbox.

Example: <input type="text" onchange="myFunction()">


onsubmit: This function is used to trigger a script or action when a form is submitted. It can be used with the <form> tag.

Example: <form onsubmit="myFunction()"> ... </form>


onload: This function is used to trigger a script or action when a web page or element has finished loading. It can be used with various elements such as the <body> tag and images.

Example: <body onload="myFunction()"> ... </body>


These are just a few examples of the functions that can be used in HTML. It's important to note that the actual scripting language used to define the functions is usually JavaScript, and it should be included in a separate <script> tag within the HTML document.


Some common HTML attributes are:


id: This attribute is used to uniquely identify an element on a web page. It is often used to reference elements in CSS and JavaScript.

Example: <div id="header"> ... </div>


class: This attribute is used to define a class for an element. It is often used to group similar elements together for styling purposes in CSS.

Example: <div class="container"> ... </div>


style: This attribute is used to add inline styles to an element. Inline styles override external CSS styles.

Example: <p style="color: red;">This text is red.</p>


href: This attribute is used to define the URL (Uniform Resource Locator) of a hyperlink. It is used with the <a> tag.

Example: <a href="https://www.example.com">Visit Example.com</a>


src: This attribute is used to define the URL of the source file for an image or multimedia element. It is used with the <img> and <video> tags.

Example: <img src="example.jpg" alt="Example Image">


alt: This attribute is used to provide alternative text for an image. It is important for accessibility purposes, as it is read by screen readers for visually impaired users.

Example: <img src="example.jpg" alt="Example Image">


These are just a few examples of HTML attributes. There are many more that can be used to control the behavior and appearance of HTML elements.

No comments: