Tag Archives: JavaScript

Verificar se valor existe na String Javascript

Algumas formas de verificar se valor existe em uma string utilizando JavaScript. 1. (ES6) includes [js] var string = “foo”, substring = “oo”; string.includes(substring); [/js] 2. search [js] var string = “foo”, expr = “/oo/”; string.search(expr); [/js] 3. lodash includes [js] var string = “foo”, substring = “oo”; _.includes(string, substring); [/js] 4. RegExp [js] var […]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , | Leave a comment

Remover DIV pelo texto ou title

Simples forma de remover uma div pelo text ou title. [js] $(“[title=’Criar novo site de projeto’]”).remove(); $(“[text=’Criar novo site de projeto’]”).remove(); [/js]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript, JQuery | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> , | Leave a comment

Função JavaScript para validação de CPF

Função para validação de CPF. [js] /*Função que valida Cpf*/ function validarCPF( campo ){ var cpf = campo.value; cpf = remove(cpf, “.”); cpf = remove(cpf, “-“); if(cpf.length != 11 || cpf == “00000000000” || cpf == “11111111111” || cpf == “22222222222” || cpf == “33333333333” || cpf == “44444444444” || cpf == “55555555555” || cpf […]

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> | Leave a comment

Sleep “Thread” em JavaScript

O exemplo que mostro a seguir mostra como fazer uma “thread sleep” via JavaScript. [js] function sleepFor( sleepDuration ){ var now = new Date().getTime(); while(new Date().getTime() < now + sleepDuration){ /* do nothing */ } } [/js] Exemplo de uso [js] function demo(){ sleepFor(2000); console.log("Olá! Eu sou um teste."); } demo(); [/js] Prático!

<span class="entry-utility-prep entry-utility-prep-cat-links">Posted in</span> AngularJS, JavaScript | <span class="entry-utility-prep entry-utility-prep-tag-links">Tagged</span> | Leave a comment