This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log( $('#precisaExistir').length ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $el = $('#precisaExistir'); | |
if ($el.length) { | |
$el.css('backgroundColor', 'green'); | |
} else { | |
alert('Deu pau aqui tio.'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $el = $('#precisaExistir'); | |
if ($el.length) { | |
$el.css('backgroundColor', 'green'); | |
} else { | |
throw '#precisaExistir não encontrado.'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $el = $('#precisaExistir'); | |
//realizamos testes primeiro | |
if (!$el.length) { | |
throw '#precisaExistir não encontrado.'; | |
} | |
//passou pelos testes básicos, executamos a funcionalidade da função/script | |
$el.css('backgroundColor', 'green'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//para testar se nosso objeto jQuery possui elementos: | |
if ($el.length) {/*...*/} | |
//isto é equivalente à: | |
if ($el.length !== 0) {/*...*/} | |
//Já que .length sempre é um número >= 0, também podemos escrever: | |
if ($el.length > 0) {/*...*/} | |
//e para ver se não possui nenhum elemento: | |
if (!$el.length) {/*...*/} | |
//isto equivale à: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('html').appendTo('body'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#foo').css('border-radius', 10); | |
$('#foo').css('borderRadius', 10); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.getElementById('foo').style.borderRadius = '10px'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
element.style.border-radius = //[...] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var o = { 'foo-bar!@ #': 1 }; | |
console.log( o['foo-bar!@ #'] ); //1 |