Category Archives: Html

Drag and drop from scratch using JavaScript

An example code to implement drag-ability in to an HTML element from scratch without using JavaScript library. JavaScript functions to provide drag-ability: function DDElement(ele, event) { addEvent(ele, “mousedown”, downHandler, true); addEvent(document, “mouseup”, upHandler, true); if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true; if (event.preventDefault) event.preventDefault(); else event.returnValue = false; function upHandler(e) { e = e ||…

Read More

Cross browser event listener

Sometimes, we need to attach or detach an action with an element for specific event where listener function depends on browser. By using following code snippet anyone can do that in all browsers: function addEvent(obj, evType, fn, useCapture) { useCapture = (useCapture === undefined ? false : useCapture); if (obj.addEventListener) { obj.addEventListener(evType, fn, useCapture); }…

Read More

HTML coding guidelines

This is my third article about coding guidelines. In this article I wanted to give you some general guidelines for HTML coding that will help to improve readability, maintainability and code reuse. It will reduce browser related problem. Following are some guidelines: Must be use doctype in your web page. Everyone should be write well-formed…

Read More

Specify rendering engine of IE

Internet Explorer 8 supports different document compatibility to ensure that your web pages have a consistent appearance in future versions. If you are having trouble on a site in different IE, you can use specific rendering mode to display your web pages by using simple META tag. Below is the META tag to use IE7…

Read More