Category Archives: Javascript

element.insertAdjacentHTML

insertAdjacentHTML() parses the specified text as HTML or XML and inserts the resulting nodes into the DOM tree at a specified position. It does not reparse the element it is being used on and thus it does not corrupt the existing elements inside the element. This, and avoiding the extra step of serialization make it… Read More »

Difference between .children and .childNodes

Consider following code: <ul> <!– Comment –> <li>Node 1</li> <li>Node 2</li> </ul> .children.length returns 2 but .childNodes.length returns 5 everything is because there are text nodes before, after and between LI elements. Remember that IE 6-8 threats comments as nodes, so children.length in these browsers returns 3 instead of 2. Suppored in all browsers. Similar… Read More »

Formula for calculating size of the scrollbar

The formula is very simple, and returns almost identic results (tested on OSX). size = (element_height / element_scroll_height) * element_height and similar for horizontal one: size = (element_width / element_scroll_width) * element_width In JS: var size = (el.offsetHeight / el.scrollHeight) * el.offsetHeight; In JS + JQ: var size = ($el.height() / el.scrollHeight) * $el.height();