Forums/Community/Zendesk Apps

Tip: use wrapping label tags instead of "for"

James Rosen
posted this on September 19, 2012 13:55

If you are building an app that displays form elements with labels, avoid the <label for="..."> syntax. Instead, use <label><input.../></label>. The problem with the for version is that it relies on unique DOM element IDs on the page. Apps that can be installed multiple times per help desk will end up writing multiple elements with the same ID to the DOM, and the browser will have no way to know which form element to tie to which label.