How to think of Javascript-is this accurate? -


I am working through some JavaScript examples, and I have done this:

 < Code> & lt ;! DOCTYPE HTML PUBLIC "- // W3C // DTD XHTML 1.0 Stronger // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Page Title & lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Function display text () {document.getElementById ('targetDIV'). InnerHTML = "You are using JavaScript"; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body onload = "displayText ()" & gt; & Lt; H2 & gt; It should be before other lessons. & Lt; / H2 & gt; & Lt; Div id = "targetDIV" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt; Well, very basic, I know - but I realized that I was confused about "why" of some things. Is it true that: 

will be function = WHAT .

Call (body loading ...) = WHEN

and div id = "targetDIV" = where will be < / P>

I know that this is the case in this example, but in general is the way things are used in javascript?

Yes, this is a very good model to carry your head.

Onload for the body is called an event and many object events are released. Your function is called the display text in response to the download event and so is an event handler.

The code inside your function can do anything, but in this case it loads some text dynamically in a tag on your page.

There are other things to look for in this regard. You access the tag using document.getElementById. The document is available for you in JavaScript, which includes a model of the page titled Dom or Document Object Model. It is extremely powerful because it presents the hierarchical layout of everything on your page and allows you to manipulate the content.

getElementById () is a very useful job that searches for the DOM tree and gives the id what you specify, it is a type of search because the text gets your tag because You added the target id id to the div tag and so you can get it through the DOM function.

Welcome to programming in javascript. Now you have a busy working model, you will actually find the weight of clever things you can do and your life as a web programmer will never be ever again.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -