Skip to content

Instantly share code, notes, and snippets.

@sindre
Forked from anonymous/ipadlabels
Created June 21, 2011 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sindre/1038035 to your computer and use it in GitHub Desktop.
Save sindre/1038035 to your computer and use it in GitHub Desktop.
iOS Label fix
var iPadLabels = function () {
function fix() {
var labels = document.getElementsByTagName('label'),
target_id,
el;
for (var i = 0; labels[i]; i++) {
if (labels[i].getAttribute('for')) {
labels[i].onclick = labelClick;
}
}
};
function labelClick() {
el = document.getElementById(this.getAttribute('for'));
if (['radio', 'checkbox'].indexOf(el.getAttribute('type')) != -1) {
el.setAttribute('selected', !el.getAttribute('selected'));
} else {
el.focus();
}
};
return {
fix: fix
}
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment