Category Archive: JavaScript

Examples of various functions and methods to common javascript problems.

Oct 23

Match Numbers using RegExp

Since I use JavaScript as one of my primary development languages, I tend to need little helper functions to accomplish small tasks. One in particular I’ve needed more than any other is the ability to match a number, no matter how it was formatted. I found the following RegExp expression that has worked well for …

Continue reading »

Oct 30

Format Phone Numbers in JavaScript

Here is a quick function that will grab any group of integers from a string so you may format phone numbers (or any number based formatting) quickly. By default this function formats phone numbers in standard 7 digit or 10 digit formatting. Example: 123-4567 and (123) 456-7890. The function matches all digits from a string. …

Continue reading »

Oct 29

SharePoint 2013 Workspace Scroll Issue Fix

Some of you may have run into an issue using SharePoint 2013 where the SharePoint created div #s4-workspace does not properly set the height and width of the workspace container. I have run into this problem for accounts not granted administrative privileges (the accounts that are unable to see the SharePoint ribbon). A quick fix …

Continue reading »

Jul 07

Verify jQuery Version is at Least 1.x.x

Small function to verify if the jQuery library loaded is at least version 1.x.x (where you define the minimum version). Note this function does NOT need jQuery loaded to work, so you can use it to check if jQuery is loaded and version compare if you wish. if (jqueryGreaterThan(‘1.4.4’)) { // jQuery passed version verification, …

Continue reading »

Jun 30

Attach .scroll() to AJAX loaded content

If you need to listen for a scroll event on AJAX loaded content that is not the window.scroll or document.scroll you may have realized that the .scroll() event does not bubble. All hope is not lost, you can still achieve this (especially if you are needing to do it with an element with overflow:auto; or …

Continue reading »

Mar 20

Replace default hashtag scrolling in browser

Tired of the fluid-less jumps when going to a URL with a #hashtag? You can replace this using jQuery’s .scrollTo() method in the document.ready of your javascript. Here’s an example: $(document).ready(function() { if(window.location.hash) { $(‘html, body’).animate({ scrollTop: $(window.location.hash).offset().top }, 1000); } }); Now on page load this will fluidly scroll to the DOM element you’ve …

Continue reading »

Feb 19

jQuery UI Rename Tabs

I found myself in the position of needing jQuery UI’s tabs plugin to have the option of being renamed while still maintaining the tab. I came up with this function to easily rename a tab by passing the tab’s id selector and desired value. function renameTab(selector, value) { $(‘a[href=”‘ + selector + ‘”‘).text(value); } Keep …

Continue reading »

Feb 24

Add jQuery code to AJAX loaded content

You may have noticed you cannot pass jQuery functions to content loaded using AJAX technology simply. One way is to use the jQuery .live() event. This can be used with a number of handlers and events to automatically pass functions to dynamically loaded content. The example below shows how you can add fancybox to a …

Continue reading »