Skip to content

Instantly share code, notes, and snippets.

View UltCombo's full-sized avatar

Fabricio Matte UltCombo

View GitHub Profile
input.checked = input.checked ^ 1;
input.checked = true ^ 1; //converte implicitamente true para 1; false para 0
input.checked = 1 ^ 1;
$('input')[0].checked ^= 1;
var input = $('input')[0];
input.checked = input.checked ^ 1;
input.checked = 1 ^ 1; //1 e 1 são iguais (não me diga?)
input.checked = 0;
input.checked = 0;
input.checked = false;
1 ^ 1 === 0 //checkada (1) é == 1 então retorna 0
0 ^ 1 === 1 //não checkada (0) é != 1 então retorna 1
>>> +''
<<< 0
>>> [1, 2].toString()
<<< "1,2"
>>> [1, 2] == '1,2'
<<< true
$('#IDinexistente').css('backgroundColor', 'green');
document.getElementById('IDinexistente').style.backgroundColor = 'green';
//com jQuery
$('#talvezExista').css('backgroundColor', 'green');
//JS nativo
var el = document.getElementById('talvezExista');
if (el) {
el.style.backgroundColor = 'green';
}