Reasons why id based selectors don't work
- The element/DOM with id specified doesn't exist yet.
- The element existexists, but it is not registered in DOM [in case of HTML nodes appended dynamically from ajaxAjax responses].
- moreMore than one elementselement with the same id areis present which is causing a conflict.
solutionsSolutions
tryTry to access the element after its declaration or alternatively use stuff like
$(document).ready();forFor elements coming from ajaxAjax responses, use the
.bind()method of jquery, olderjQuery. Older versions of jqueryjQuery had.live()for the same.useUse tools [eg[for example, webdeveloper plugin for browsers] to find duplicate ids and remove them.