Skip to main content

Posts

Showing posts from February, 2015

JavaScript: REFERRER

The browser stores some information about HTTP request headers. They're useful for many purposes. One of the headers is the referral information. It's the previous referring URL of the current URL. URL Referrer Concept This post has links to another posts. If we go to any of those (click the link), then this URL will be the referrer of that link. Similar to ordinary referral (referring) concept in daily life, but within web (HTTP) realm. Legendary Misspelling Year Context Spelling Used Notes Pre-1996 (until now) Standard English Referrer ✅ The correct spelling in proper English. 1996 HTTP/1.0 Specification (RFC 1945) Referer ❌ A typo in the RFC that became part of the official HTTP header. It was never corrected to preserve backwards compatibility. Late 1990s - Early 2000s ...

JavaScript: outerHTML

This JavaScript method will work on Internet Explorer 8 and above , and of course on latest Chrome, Firefox, Opera, etc. Just like innerHTML method, this one can also do the get or set process for an HTML DOM element. The Difference With the innerHTML method, we can get or set the content of a particular parent element, the inner part. With the outerHTML method, we will get or set the parent element reference itself. Syntax It's the same as innerHTML method. Get var parent_element = someElement.outerHTML; The variable parent_element will have all the content plus the parent element of that someElement variable. Set someElement.outerHTML = "<div id='replacement'>New content</div>"; The variable someElement (which is the representation of a particular DOM element) will all be replaced with the new content plus the wrapper (parent element) declared above. That's about it. You can try it out on CodePen or oth...

JavaScript: The Difference between innerHTML and innerText

The basic These methods can do the get or set process. On Firefox (I was using Chrome), the innerText method doesn't work. Firefox uses textContent instead. It will work like innerText but a bit different, you can compare the string-only output using Firefox and Chrome. Internet Explorer supports innerText method by default. GET The JavaScript innerHTML will capture everything inside the element reference (the parent). USAGE var inner_html = the_parent_element.innerHTML; The inner_html variable will consist of HTML elements inside the_parent_element . The jQuery equivalency of innerHTML (get) is $(parent).html() The innerText will capture only the string (plus the escaped HTML tags) inside the element reference. All other will be stripped out. USAGE var inner_text = the_parent_element.innerText; The inner_text variable will consist of text (string) inside the_parent_element . The jQuery equivalency of that is $(parent).text() SET The Ja...