Teaching method objects, properties and events in JavaScript web programming
5 minute(s) read | Published on: Jun 04, 2021 Updated on: Dec 14, 2021 |
You definitely know that programming can provide you with a good income, and in addition to the good income you can have from this way, it also allows you to not get tired while doing work and continue to work with interest, due to the fact that there is so much variety in this world and if you are interested in it, you can continue your journey with pleasure.
Programmers need to master different programming languages, one of the most important ones they need to master is JavaScript which we are going to continue to explore its various features, but before that it is necessary to explain the language briefly.
What is JavaScript-web programming language?
It is a language that is used to implement a variety of complex features in web pages and causes complex applications to run on web pages which encourages the user to visit those pages and also due to the high interaction that the user can have with the page with the help of this language, they will gain a positive user experience, so that you can attract lots of users to your website day by day.
JavaScript-Object Methods:
Objects in JavaScript are a set of key-value pairs, these values can include specifications and methods, and in addition, it may include other types of data in this language, which we are going to examine further in the following, here consider the following example.
This:
When defining a function "this" is pointing to the owner of the function, so that you can better understand the example below.
Methods:
Methods in this language are actually operations that can be done on objects.
toUpperCase ():
This method can be used for text strings.
Adding a Method to an Object:
One of the easiest things to do in this section is to add a method to objects.
JavaScript-Properties:
Properties are actually values associated with an object, these properties can be changed, added and deleted or may have none of these capabilities and can only be read, in order to add these properties to objects, it is necessary to follow the rules below.
Another possibility that exists in this field is that you can delete or remove various properties.
Adding New Properties:
Delete:
While using this feature, you should follow all the available tips, because with a wrong movement, your whole program may be damaged, there are rules in this regard, for instance, the delete operator should not be used on predefined JavaScript object properties, if you do, as we have mentioned, the program may be damaged.
JavaScript-Events:
In simple terms, it means the occurrence of an event that occurs on a web page after which, the JS interpreter identifies it and finally shows a reaction according to that event, it should be noted that in general each function is connected to one or more events, now consider the following example.
Second example:
Different methods can be used to let JavaScript-work with events:
• HTML event attributes can execute JavaScript code directly
• HTML event attributes can call JavaScript functions • You can assign your own event handler functions to HTML elements • You can prevent events from being sent or being handled
Handle:
There are three ways to attribute an event to an element, as follows which we are going to mention below.
- Using the event with addEventListener and removeEventListener
- Using the event with an independent Event Handler outside the HTML coding - Using the event with Inline Event Handler and combine with HTML coding
There are several commonly used events, some of which are listed below.
List of frequently used JavaScript-events on web pages:
- ondblclick:
This is one of the most commonly used events that can happen on web pages, in fact this event refers to a time when a target element on a web page is double-clicked in a very short period of time.
- onclick:
As its name implies, this event refers to when the target element is clicked on the web page.
- onfocus:
This event occurs when the target element on the web page becomes focused, in which case you should keep in mind that not all elements on the web page can be focused.
- onkeydown:
Among the most common events that may occur on web pages, it occurs when the user holds down a key on the keyboard.
- onkeyup:
This will also happen when the user releases the pressed button.
- onmouseover:
This event also occurs when the mouse pointer enters within the specified range of the element.
- onmousemove:
This event will also occur when the mouse pointer is moved within the specified range of the element.
- onmouseout:
This will happen when the mouse pointer goes out of range of the element.
- onload:
This event will occur when the resource is fully loaded.
- oncopy:
This event will occur when you try to copy content.
- oncut:
It happens by cutting content from the source of the event.
- onscroll:
This event will occur when the page or also an element is scrolled.
- onsubmit:
There are many frequently used events, including the one that will occur when you submit a form.
Last word:
method objects, properties and events in JS programming language are some of the items that each of them are of a great importance, and it is necessary to have the mastery of all items in this language, including these items, in order to be successful, in this article we have mentioned some points in relation to each item, we hope that the information which have been provided can be helpful for you.
Click to analyze your wesbite SEO