toggleClass and remove class from all other elements

This will do it $(“.size a”).click(function(){ $(‘.size a.checked’).not(this).removeClass(‘checked’); $(this).toggleClass(‘checked’); }) Update Alternatively you could do $(“.size”).on(‘click’,’a’, function(){ $(this).toggleClass(‘checked’).siblings().removeClass(‘checked’); })

Use jQuery to detect whether a device can make telephone calls (supports “tel://” protocol)

I’m not sure about Android or BlackBerry, but iOS will automatically pick up telephone numbers and wrap them like so: <a href=”https://stackoverflow.com/questions/17345177/tel:xxx”>xxx</a>…so you could have a hidden <div> somewhere that contains a phone number like 1-800-555-5555, then, on page load do something like this: var isTelephone = $(“a[href*=’tel:’]”).length > 0; This may or may not … Read more

jQuery UI Datepicker – Disable specific days

Here is a way to disable specific dates from being selected: var unavailableDates = [“9-5-2011″,”14-5-2011″,”15-5-2011”]; function unavailable(date) { dmy = date.getDate() + “-” + (date.getMonth()+1) + “-” + date.getFullYear(); if ($.inArray(dmy, unavailableDates) < 0) { return [true,””,”Book Now”]; } else { return [false,””,”Booked Out”]; } } $(‘#iDate’).datepicker({ beforeShowDay: unavailable }); Source: jQuery – Datepicker – … Read more

$(window).unload is not firing

Actually some browsers such as Google Chrome might block if you attempt to alert in a window unload. As a user I like this feature. Alerting every time you try to navigate away from a page sucks: Replace the alert with a console.log or something else less intrusive to the user and the event will … Read more

Using javascript and jquery, to populate related select boxes with array structure

I prefer data structure like this: var carMakers = [ { name: ‘Honda’, models: [ { name: ‘Accord’, features: [‘2dr’, ‘4dr’] }, { name: ‘CRV’, features: [‘2dr’, ‘Hatchback’] }, { name: ‘Pilot’, features: [‘base’, ‘superDuper’] } ]}, { name: ‘Toyota’, models: [ { name: ‘Prius’, features: [‘green’, ‘superGreen’] }, { name: ‘Camry’, features: [‘sporty’, ‘square’] … Read more