Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

Reasons why id based selectors don't work

  1. The element/DOM with id specified doesn't exist yet.
  2. The element existexists, but it is not registered in DOM [in case of HTML nodes appended dynamically from ajaxAjax responses].
  3. moreMore than one elementselement with the same id areis present which is causing a conflict.

solutionsSolutions

  1. tryTry to access the element after its declaration or alternatively use stuff like $(document).ready();

  2. forFor elements coming from ajaxAjax responses, use the .bind() method of jquery, olderjQuery. Older versions of jqueryjQuery had .live() for the same.

  3. useUse tools [eg[for example, webdeveloper plugin for browsers] to find duplicate ids and remove them.

Reasons why id based selectors don't work

  1. element/DOM with id specified doesn't exist yet.
  2. element exist but is not registered in DOM [in case of HTML nodes appended dynamically from ajax responses]
  3. more than one elements with same id are present which is causing conflict.

solutions

  1. try to access element after its declaration or alternatively use stuff like $(document).ready();

  2. for elements coming from ajax responses, use .bind() method of jquery, older versions of jquery had .live() for the same.

  3. use tools [eg webdeveloper plugin for browsers] to find duplicate ids and remove them.

Reasons why id based selectors don't work

  1. The element/DOM with id specified doesn't exist yet.
  2. The element exists, but it is not registered in DOM [in case of HTML nodes appended dynamically from Ajax responses].
  3. More than one element with the same id is present which is causing a conflict.

Solutions

  1. Try to access the element after its declaration or alternatively use stuff like $(document).ready();

  2. For elements coming from Ajax responses, use the .bind() method of jQuery. Older versions of jQuery had .live() for the same.

  3. Use tools [for example, webdeveloper plugin for browsers] to find duplicate ids and remove them.

Source Link
Sumit Kumar
  • 1.9k
  • 19
  • 20

Reasons why id based selectors don't work

  1. element/DOM with id specified doesn't exist yet.
  2. element exist but is not registered in DOM [in case of HTML nodes appended dynamically from ajax responses]
  3. more than one elements with same id are present which is causing conflict.

solutions

  1. try to access element after its declaration or alternatively use stuff like $(document).ready();

  2. for elements coming from ajax responses, use .bind() method of jquery, older versions of jquery had .live() for the same.

  3. use tools [eg webdeveloper plugin for browsers] to find duplicate ids and remove them.