design patterns - What mechanism in JavaScript causes a change in DOM or CSSStyleDeclaration to trigger a redraw of the page? -


i think take granted whenever change dom element's property or cssstyledeclation object's property, page redrawn:

http://jsfiddle.net/peqtl/

document.getelementbyid("foo").innerhtml = "bar"; document.getelementbyid("foo").style.padding = "30px"; 

but think it, .style returns cssstyledeclaration object, , padding returns property. set property, , how trigger , cause page different?

i thinking, classic "observer pattern", page renderer register every dom element , cssstyledeclaration object that, whenever property changes, notify renderer redraw part of page?

or, isn't true that, if change something, whole page can affected: example, z-index affect , siblings' "cover up" order, need redraw parent node , down tree, or if element has position: relative or position: absolute, can affect element on page @ all, whole page needs redrawn. in other words, renderer may not need register every dom elements , cssstyledeclaration object. render need register top level dom object (either document or <html> tag element, document.documentelement , simple implementation is, change property or offspring's property, notify renderer redraw whole page. whenever value of property, renderer doesn't need notified redraw page.

and "observer pattern" internal dom , javascript engine -- is, can't touch or know how done underneath?

i know implementation supposed hidden , unknown user of html , javascript, programming standpoint hope know practical way can implemented, part of software system.

a way implement pattern use of css class. should avoid modify dom features of each html elements. modify visual aspect of html element set or add new class. in following can see simple example:

    //html     first name: <input type="text" id="fmame" class="mandatory">     last name:  <input type="text" id="lname" class="mandatory" value="blablabla">      //javascript     var inputs = $("input");     (var = 0, j = inputs.length; < j; i++) {         if (inputs[i].classname === 'mandatory' && inputs[i].value === '')             inputs[i].classname += ' error';     }      //css     .error {         background-color: red;     } 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -