Created
October 23, 2014 02:26
-
-
Save vcavalcante/133dda036b152208dbb3 to your computer and use it in GitHub Desktop.
Usando querySelectorAll no lugar do jQuery retornando array de itens // source http://jsbin.com/nivafaciqu
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Usando querySelectorAll no lugar do jQuery retornando array de itens" /> | |
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
span{ | |
display:block | |
} | |
</style> | |
</head> | |
<body> | |
<ul> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
</ul> | |
<script id="jsbin-javascript"> | |
$("li.nome").each(function(index, element) { | |
$(element).text("Olá: "+ index); | |
}); | |
//Opção3 | |
/* | |
function $t(selector) { | |
return [].slice.call(document.querySelectorAll(selector)); | |
} | |
$t("li.nome").forEach(function(element, index) { | |
element.innerText= "Olá: "+ index; | |
}); | |
*/ | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Usando querySelectorAll no lugar do jQuery retornando array de itens" /> | |
<script src="//code.jquery.com/jquery-2.1.1.min.js"><\/script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<ul> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
<li class="nome"></li> | |
</ul> | |
</body> | |
</html></script> | |
<script id="jsbin-source-css" type="text/css">span{ | |
display:block | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">$("li.nome").each(function(index, element) { | |
$(element).text("Olá: "+ index); | |
}); | |
//Opção3 | |
/* | |
function $t(selector) { | |
return [].slice.call(document.querySelectorAll(selector)); | |
} | |
$t("li.nome").forEach(function(element, index) { | |
element.innerText= "Olá: "+ index; | |
}); | |
*/</script></body> | |
</html> |
This file contains 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
span{ | |
display:block | |
} |
This file contains 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
$("li.nome").each(function(index, element) { | |
$(element).text("Olá: "+ index); | |
}); | |
//Opção3 | |
/* | |
function $t(selector) { | |
return [].slice.call(document.querySelectorAll(selector)); | |
} | |
$t("li.nome").forEach(function(element, index) { | |
element.innerText= "Olá: "+ index; | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment