JS / jQuery

Jquery and javascript snippets that would help in solving quick and easy problems.


Drag and drop on mobile devices

Drag and drop on mobile devices I had a problem in the past with a draggable and droppable calendar with jQuery and ajax. When you add drag and drop to a web page using JavaScript, such as jQuery UI draggable and droppable, you obtain a problem. The dragging and dropping are intercepted by the phone

How to select all anchors with display block jquery

snippets

How to select all anchors with display block jquery Very often or not, you need to select all the elements from within the DOM, that have their display property set to “block”. Solution

Filter function from jQuery to the rescue. Description: Reduce the set of matched elements to those that match the selector or pass

Disable jqueryui calendar days EXCEPT the mondays of every week

datepicker

Disable jqueryui calendar days EXCEPT the mondays of every week Let’s say you want the user to be able to see all days from within the month, but to be able to select only the mondays of every week.

Here is a DEMO. You can disable all “Sundays” by switching from “day == 1”

How to redirect URL in Javascript or jQuery

snippets

How to redirect URL in Javascript or jQuery I will present some ways to redirect the user to another page from the client side using only plain javascript. 1) Using window.location.href you obtain a similar behavior  as an HTTP redirect

2) Using window.location.replace

window.location.href VS window.location.replace It is better than using window.location.href, because replace() does not put

Change value of selectbox in Zurb Foundation via JavaScript

snippets

Change value of selectbox in Zurb Foundation via JavaScript Some of us tried to change or will have to change via javascript a select-box that is generated from the custom forms of Zurb Foundation  framework. You noticed or you will notice that it is not as simple as changing a default html select-box. Why ?

PHP explode equivalent for javascript

snippets

PHP explode equivalent for javascript Very often you have to perform operations on strings to split them, to obtain only a desired piece of it. If the string is formatted in a way that allows you to split, eg. you know the delimiters, you can use the following way to do this. Problem Let’s say

How to create a while loop in Javascript

snippets

How to create a while loop in Javascript As I said in one my earlier articles, I’ll try porting every script to all programming language we’ve set the category for, this time is for javascript. Scenario Create a counting script that stops once it reaches 10 and alerts the user the execution has finished. Solution

How to parse URL using javascript

snippets

How to parse URL using javascript In certain cases you may want to parse a URL using javascript, although I don’t specifically recommend this, rather you should use a php approach, server side. Javascript can be manipulated and if passing the URL somewhere and then actually doing work with the result, you may have surprises

Request an article ←