Skip to content

Instantly share code, notes, and snippets.

@lambdamusic
lambdamusic / Snipplr-40795.js
Last active April 4, 2024 22:05
JavaScript: Regex Selector for jQuery #js
jQuery.expr[':'].regex = function(elem, index, match) {
var matchParams = match[3].split(','),
validLabels = /^(data|css):/,
attr = {
method: matchParams[0].match(validLabels) ?
matchParams[0].split(':')[0] : 'attr',
property: matchParams.shift().replace(validLabels,'')
},
regexFlags = 'ig',
regex = new RegExp(matchParams.join('').replace(/^\s |\s $/g,''), regexFlags);
@lambdamusic
lambdamusic / Snipplr-27094.js
Last active April 4, 2024 22:05
JavaScript: js: setTimeout #js
setTimeout(“inittab1();“, 500);
setTimeout(“inittab2();“, 1000);
setTimeout(“inittab3();“, 2000);
setTimeout(“initontology();“, 6000);
@lambdamusic
lambdamusic / Snipplr-42627.js
Last active April 4, 2024 22:05
JavaScript: Forcee a page to reload #js
// This will forcefully reload the current page. No jQuery needed here.
location.reload(true);
// If your content might be cached by proxy servers and your URL has no query string, try this:
location.replace(
location.href.replace(/\?.*$/, '') + '?' + Math.random());
@lambdamusic
lambdamusic / Snipplr-40794.js
Last active April 4, 2024 22:05
JavaScript: Case insensitive jQuery :contains selector #js
// For jQuery 1.2
jQuery.extend(
jQuery.expr[':'], {
Contains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0"
});
// For jQuery 1.3 (thanks @user95227) and later you need
@lambdamusic
lambdamusic / Snipplr-44947.js
Last active April 4, 2024 22:05
JavaScript: Running scripts ciclically #js
<html>
<body>
<input type="text" id="clock" />
<script language=javascript>
var int=self.setInterval("clock()",1000);
function clock()
{
var d=new Date();
var t=d.toLocaleTimeString();
@lambdamusic
lambdamusic / Snipplr-25271.js
Last active April 4, 2024 22:05
JavaScript: Check if array is empty in javascript #js
if (testarray.length <1) alert("array is empty");
//or
if(A && A.length==0)
//or if you have other objects that A may be:
if(A && A.constructor==Array && A.length==0)
@lambdamusic
lambdamusic / Snipplr-39839.js
Last active April 4, 2024 22:05
JavaScript: JS: open popup window #js
// construct for explorer compatibility
var newwindow = '';
// EG: pop_up_window("http://www.google.com", 200, 200)
function pop_up_window(url, sizeh, sizew) {
if (!newwindow.closed && newwindow.location) {
newwindow.location.href = url;
}
else {
newwindow=window.open(url,'name','height=' + sizeh + ', width=' + sizew + ', status=1, resizable=1, location=1, scrollbars=1 '); /*resizable=1*/
if (!newwindow.opener) newwindow.opener = self;
@lambdamusic
lambdamusic / Snipplr-39840.js
Last active April 4, 2024 22:05
JavaScript: JS: open multiple popUps #js
popupWins = new Array();
function windowOpener(url, name, args) {
/*******************************
the popupWins array stores an object reference for
each separate window that is called, based upon
the name attribute that is supplied as an argument
*******************************/
if ( typeof( popupWins[name] ) != "object" ){
popupWins[name] = window.open(url,name,args);
@lambdamusic
lambdamusic / Snipplr-42632.js
Last active April 4, 2024 22:04
JavaScript: Verify if an html element is empty #js
if ($('#keks').html()) {
// Do something to remedy the situation
}
@lambdamusic
lambdamusic / toggle.js
Last active April 4, 2024 22:04
Jquery: click and toggle #js
$('#clickme').click(function() {
$('#book').toggle('slow', function() {
// Animation complete.
});
});