js---4th unit Flashcards
DOM
- According to W3C, Tom is platform and language neutral interface that allows programmes and scripts to dynamically access and update the content structure and style of the document
- Document object represents the whole html document
- When HTML document is loaded in the browser it becomes document object
- It is the root element that represents the html document
- It has its own properties and methods
- With the help of document object we can add dynamic content to our web page
props of DOM
flow chart
methods of DOM
- write(“str”)
- writeln(“str”)
- getElementById(‘‘id’’)
- getElementByName(‘‘name’’)
- getElementByTagName(“tag”)
- getElemntByClassName(“cls”)
innerHTML
- Inner html property can be used to write dynamic html and html document
- It is used mostly in the web pages to generate the dynamic html such as registration form, comment form, links etc.
<script> function showcommentform() { var data="Name:<input type='text' name='name'><br>Comment:<br><textarea rows='5' cols='80'></textarea> <br><input type='submit' value='Post Comment'>"; document.getElementById('mylocation').innerHTML=data; } </script>
<form>
<input></input>
<div></div>
</form>
events and event handling
- event: Change in the state of an object is called as an event
- in HTML there are various events which represent that some activities performed by the user or by the browser
- When javascript code is included in Html javascript react over these events and allow the execution this process of reacting over events is called as event handling
- tus javascript handles the html events via event handlers
Mouse events
- Click
- mouseover
- mouseout
- mousedown
- mouseup
- mousemove
Keyboard events
Keydown and keyup
form events
- Focus – Users focus on an element
- submit – Submits the form
- blur — Her focus is away from formally
- Change – When user modifies or changes the value of a form element
window/doc eve
- Load(Browser finishes loading of the page)
- unLoad (When visitor leaves the current web page the browser unloads)
- resize (When visitor resizes the window of the browser)
add eventlistener
- add event listener method attaches in event handler to the specified element
- It attaches without overwriting existing event handlers
- You can add many handlers to one element
- You can Add event listeners 2HTML elements and dom objects also
- When using event cleaser method the js is separated from html markup for better readability and allows you to add event listeners even when you dont control html
syn of Add and remove event listener
addEventListener(“event”,fun(calling/decl),useCapture)
removeEventListener(“event”,function)
Event bubbling and even capturing
addEventListener(event, function, useCapture)
useCapture
1. There are two ways of even propagating html:
i) bubling
ii) capturing
2. Event propagation is the way of defining the element order when element occurs
3. Let’s say <P> is decalred in <div> tag and the user clicks on P element which elements clicked event should be handled first
4. bubbling(true): In bubbling first in innermost elements are handled then the outermost(<div>)
5. capturing(false): In capturing outermost element(<div>) is handled first and then in innermost(<P>)
- By default it is declared as false that is capturing…………. If we declare it as true then it becomes bubbling