Skip to content

Instantly share code, notes, and snippets.

@ricmetal
ricmetal / gist:3806630
Created September 30, 2012 12:27
jQuery Focus()
Always set focus after unhiding an element. IE freaks out over this;
Focus isn't bulet-broof. Try:
1- Setting the value to an element before and/or after giving it focus;
2- $("input[name='titleInputField']").focus();
3- Blur then focus an element;
@ricmetal
ricmetal / gist:3802056
Created September 28, 2012 21:01
Dealing with CrossBrowser Max-Width
max-width:1280px; /* Max-width does not work in IE6 and below. */
min-width:800px; /* Min-width does not work in IE6 and below. */
_width:1000px; /* Static width for IE6 & below */
@ricmetal
ricmetal / gist:3696975
Created September 11, 2012 08:43
Getting The Height of a Hidden Div Using jQuery
/*
The idea is to remove the div from it's normal flow, make it invisible (now the div does not affect the page), and make it displayed as a block so 'it has layout'. After, get the height, and then undo it's attributes to whatever your initial attributes where and display the div as hidden.
*/
$('#hidden_div').css({'position':'absolute', 'visibility':'hidden', 'display':'block'});
var divHeight = $('#hidden_div').outerHeight(true); // outerHeight includes the paddings and borders. setting the optional value to true, includes the div's margins as well.
$('#hidden_div').css({'position':'static', 'visibility':'visible', 'display':'none'});
@ricmetal
ricmetal / gist:3380265
Created August 17, 2012 16:12
Cross-Browser Background Gradient With Image
background-color:#eee; /* no-gradient browser fallback */
background-image:url('../../../imgs/downArrow.png'); /* no-gradient browser fallback */
background-image:url('../../../imgs/downArrow.png'), -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#ddd)); /* Saf4+, Chrome */
background-image:url('../../../imgs/downArrow.png'), -webkit-linear-gradient(top, #f5f5f5, #ddd); /* Chrome 10+, Saf5.1+ */
background-image:url('../../../imgs/downArrow.png'), -moz-linear-gradient(top, #f5f5f5, #ddd); /* FF3.6+ */
background-image:url('../../../imgs/downArrow.png'), -ms-linear-gradient(top, #f5f5f5, #ddd); /* IE10 */
background-image:url('../../../imgs/downArrow.png'), -o-linear-gradient(top, #f5f5f5, #ddd); /* Opera 11.10+ */
background-image:url('../../../imgs/downArrow.png'), -linear-gradient(top, #f5f5f5, #ddd); /* W3C */
@ricmetal
ricmetal / String to 2D array
Created June 19, 2011 09:56
Populate a 2D array from a concatenated string.
var resultRaw = "3,1a_2a_3a_4a-1b_2b_3b_4b-1c_2c_3c_4c";
var charAtPos = resultRaw.indexOf(',');
var items = resultRaw.substring(0, charAtPos);
var resultVar = resultRaw.substr(charAtPos + 1);
var simpleArray = resultVar.split("-");
// simpleArray[0] = 1a_2a_3a_4a;
// simpleArray[1] = 1b_2b_3b_4b;
// simpleArray[2] = 1c_2c_3c_4c;
// simpleArray[3] = 1d_2d_3d_4d;
@ricmetal
ricmetal / gist:1006050
Created June 3, 2011 08:23
HTML Select JavaScript Tricks
// Emulate a mouse options change, when using the keyboard to change option:
<select onchange="alert('clicked');" onkeyup="this.blur(); this.focus();">
...
//Get a HTML's Select element's selected item's value:
<select onchange="alert(this.options[this.selectedIndex].value);">
...
// Get a HTML Select element's real length (using jQuery):
if($('#select_element')[0].options.length === 0) { alert('No items in select.'); }