Tag: javascript

Javascript Done Resize

Normally code in the resize event is meant to just run once when the user is done resizing.  This code below, from css-tricks and seen elsewhere will do the trick: var resizeTimer; $(window).on(‘resize’, function(e) { clearTimeout(resizeTimer); resizeTimer = setTimeout(function() {

Tagged with:

Escape strings for use in JavaScript

When using parameters from the URL, it should always be sanitized before using it in your javascript. Using jQuery you can easily do: var safeString = $(“<span></span>”).text(unsafeString).html(); Using plain javascript: var entityMap = { “&”: “&amp;”, “<“: “&lt;”, “>”: “&gt;”,

Tagged with: , ,

iPad textarea not selectable

Problem The textarea on iPad could not be selected and could not have anything entered. Solution The textarea in iPad only responds to the ‘touchstart’ event and not the ‘click’ event, but regular input accepts the ‘click’ apparently.  I some javascript where it would catch

Tagged with: , ,

Best way to detect Retina with Javascript

Best way according to W3C standards: http://stackoverflow.com/questions/19689715/what-is-the-best-way-to-detect-retina-support-on-a-device-using-javascript

Tagged with: ,

WordPress Heartbeat API

I could not find any extensive documentation on the WordPress Heartbeat API, so I am writing here to remember what I have learned through various tutorials throughout the web. The Heartbeat API is written in Javascript.  Think of it like a

Tagged with: , ,

Bootstrap Tab linking

If you use Bootstrap (v3.x) you would see that clicking on a tab does add anything to the url so if you were to refresh, you wouldn’t go back to the tab you are on.  The post below says to

Tagged with: , ,

Javascript defaultValue

For some reason I have never needed to use the defautlValue property up until today.  I was pleased to find javascript can access the original input value so tracking changes in a form is a bit easier.  However, the defaultValue

Tagged with: ,

Fancybox not working after second click

Problem Setting up fancybox 1.3.4 with inline content doesn’t work when clicking on the link twice. Solution The problem I think is with the upgraded version of jQuery.  If using jQuery 1.4 like the example, it should work fine.  But

Tagged with: ,

IE Doesn’t see padding on hover

Problem Internet Explorer 8 (I no longer even look at IE 7) seems to not be able to see the padding on an anchor tag within a ul > li > a structure.   Using jQuery I have a hover

Tagged with: , , ,

jQuery – When to use return false or preventDefault

Ran into a great article that explains the differences between return false, preventDefault and stopPropagation.  Here’s a summary: return false does both preventDefault and stopProgagation preventDefault just stops the browser default event. stopPropagation stops bubbling. In most cases you would

Tagged with: ,
Top