Skip to content

Instantly share code, notes, and snippets.

@salieridk
salieridk / gist:2633890
Created May 8, 2012 09:33
Javascript: ePageX & Y. Crossbrowser
.hover(function (e) {
this.animate({
fill: '#0a4a7a'
}, 2);
var kommunenavn = paths[arr[this.id]].name;
if (e.pageX || e.pageY) {
var leftVal = e.pageX;
var topVal = e.pageY;
@salieridk
salieridk / gist:2413139
Created April 18, 2012 12:06
CSS: reset ul
ul
{
list-style: none;
padding: 0;
margin: 0;
}
@salieridk
salieridk / gist:2405308
Created April 17, 2012 11:00
Javascript: click eventlistener
$('#divName').click(function() {
});
@salieridk
salieridk / gist:2405304
Created April 17, 2012 10:59
Javascript: Add data from JSON to <select>
var options_departments = '<option>The first option goes here<\/option>';
$.each(banks, function(i,x){
options_departments += '<option value="' + x.name + '">' + x.name + '<\/option>';
});
$("select#divName", this).html(options_departments);
$("select#divName", this).change(function(){
var index = $(this).get(0).selectedIndex;
@salieridk
salieridk / gist:2405210
Created April 17, 2012 10:42
Javascript: cleartext function
function clearText(field){
if (field.defaultValue == field.value) {field.value = '';}
else if (field.value == '') field.value = field.defaultValue;
}
<input type="text" size="25" id="test" name="test" value="indtasningsfelt" onFocus="clearText(this)" onBlur="clearText(this)">
@salieridk
salieridk / gist:2405164
Created April 17, 2012 10:33
Javascript: Self invoking function
(function() {
})();
@salieridk
salieridk / gist:2405159
Created April 17, 2012 10:30
Javascript: Check all checkboxes (button)
$('#checkIt').click(function() {
if(this.value === 'notChecked'){
$('#educationCheckbox :checkbox').each(function() {
this.checked = true; });
$('#checkIt').val('checked').html('Fjern alle');
}
else{
$('#educationCheckbox :checkbox').each(function() {
this.checked = false; });
$('#checkIt').val("notChecked").html('Vælg alle');
@salieridk
salieridk / gist:2405143
Created April 17, 2012 10:28
Javascript: check checkbox by clicking text
//makes it possible to check checkbox by clicking the associated text.
$('.checkboxes').click(function(event) {
if (event.target.type !== 'checkbox') {
$(':checkbox', this).trigger('click');
}
});