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
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
1 2 3 |
$('a').filter(function (index) { return $(this).css("display") === "block"; }) |
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
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.
1 2 3 4 5 6 |
$("#datepicker").datepicker({ beforeShowDay: function (date) { var day = date.getDay(); return [(day == 1)]; } }); |
Here is a DEMO. You can disable all “Sundays” by switching from “day == 1”
How to redirect URL in Javascript or jQuery
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
1 2 3 |
<script language=”JavaScript”> window.location.href = 'http://www.google.com'; </script> |
2) Using window.location.replace
1 2 3 |
<script language=”javascript” type=”text/javascript”> window.location.replace("http://anothersite.com"); </script> |
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
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 ?
How to create a while loop in Javascript
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
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