Showing posts from January, 2018

Javascript Tips and Tricks

Javascript Tips and Tricks Introduction In this article, we learn about import consideration while we are working with javascript.This information will help you to prevent most common mistake while development. JS tips and Tricks at one place. Description Quick tips Use  ===  while comparing two variable instead of  == Remember undefined is not null Remember javascript falsy value:    0, '', NaN, null, undefined Remember javascript truthy value:    '0', 'any string', [] (Empty array), {} (Empty object), 0 (any non-zero number)  Always declare all variables at the beginning of every scope  "use strict"; In javascript to avoid unwanted bug due to a variable. Avoid global variable declaration Reduce globals e.g var name='abc', isValid=false; Should be writen as var common={name:'abc', isValid:false}; Always declare local variables Never declare Number, String or Boolean Objects ( e.g. Never use: new Number(1), new St

Add Event To Dynamically Added Control

Introduction Sometimes in real world project we require that we can add html control dynamically to after page successfully rendered on browser.  We also require to perform certain task such as register event based on requirement. In this article we learn about how we can register event on html control which was added dynamically using jquery. Two implement this type of demo first of all we require jQuery library you can download from Here . Html Snippet: <div class="container"> <div class="body-container"> <input id="btnNew" type="button" value="Add New Button" /> <ul class="parent-ul"></ul> </div> </div> JavaScript Snippet: $(function () { console.log("DOM is READy"); // button handler which is responsible for //adding new html control $('#btnNew').click(function () { var cnt = $('