Skip to content

Instantly share code, notes, and snippets.

@mingomax
Created November 28, 2011 15:24
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 mingomax/1400761 to your computer and use it in GitHub Desktop.
Save mingomax/1400761 to your computer and use it in GitHub Desktop.
Teste se um Elemento HTML Existe com e sem Jquery
/*Com JQuery */
if( $('#id_do_elemento').length ) {
//Codigo
}
/* metodo tradicional sem JQuery */
if(document.getElementById('id_do_elemento') != null)
{
//Codigo
}
/* com o seletor do JQuery sempre nos retornará uma array de objetos tipados, logo a instrução length no auxilia nisto */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment