Posts

Showing posts with the label HTML

Javascript Basics : Part 2 (Functions)

Image
Suppose I want to change the button color when it is clicked. And to do this task, I don’t want to send the page to the server. So, what should I do? Well, HTML DOM has given us some events to work with. We will use one the events, Click event and put some code on its event. The below code will change the button color if clicked on that. Now, if we want to add another button and apply same functionality with the click, the code will like below But if you look closely, we are repeating the code. This is the worst smell of the code smells . So, we should create a method and call that method from the click event. So, how do we create a function in Javascript? Its easy. As we did before, we must add the ‘script’ tag first. Inside of this tag, we will write the function. In javascript, we must write the word ‘function’ before the name of the function. For example: function MyFunctionName() { } Then we will call that function from the event. So, if we refac...

Javascript Basics : Part 1 (Hello world)

Image
Now a days, the most basic thing a web application developer must know is Javascript. So, what is javascript? Yes..you probably know Javascript is nothing to do with Java. Javascript is totally different with Java. In syntax, in semantic, in usage, in all aspects. So, Javascript is a scripting language which runs in browser. The browser software executes the script line by line, from top to bottom, and display you the output. Now what you can guess, Javascript must be embedded in a HTML file and when the HTML codes are rendered/executed, Javascript codes get executed with those. If you want to let your browser know that you are writing a Javascript code, you must add some extra tags/codes with the statements. For example: What you can see, at the above code, by the ‘document.write’ method, we are writing some text in the browser. But we need to add the 'script' tag having the type as javascript with it. If the browser executes this line of code, we can view ‘ Javascri...

HTML Document Object Model

Image
What is it? The HTML DOM defines a standard way for accessing and manipulating HTML documents. The DOM presents an HTML document as a tree-structure. In the DOM, everything in an HTML document is a node. The DOM says: The entire document is a document node Every HTML element is an element node The text in the HTML elements are text nodes Every HTML attribute is an attribute node Comments are comment nodes Example Node tree: From the HTML above: The < html > node has no parent node; it is the root node The parent node of the < head > and < body > nodes is the < html > node The parent node of the "Hello world!" text node is the < p > node and: The < html > node has two child nodes; < head > and < body > The < head > node has one child node; the < title > node The < title > node also has one child node; the text node "DOM Tutorial" The < h1 > and < p > nodes are siblings, a...