Last active
December 19, 2015 21:09
-
-
Save IuryAlves/6018295 to your computer and use it in GitHub Desktop.
o script possui duas funções bem parecidas: body_nodes() , change_colors(new_color)
A primeira lista as cores de todos os element nodes contidos no body do html.
A segunda troca a cor de todos os element nodes para a cor espeficicada na função.
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 xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Conteudo</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
function body_nodes(){ | |
obj = document.body.childNodes; // retorna para a var obj todos os nós que estão dentro do body | |
$.each(obj, function(index, value){ // itera sobre a var obj mostrando seu indice e valor | |
if (value.nodeType == 1){ // value.nodeType retorna 1 se ele for um element node | |
name_tag = value.tagName; // retorna o nome da tag | |
console.log(name_tag + ":" + $(name_tag).css("color") ); | |
} | |
}); | |
} | |
function change_colors(new_color){ | |
obj = document.body.childNodes; | |
$.each(obj, function(index, value){ | |
if (value.nodeType == 1){ | |
name_tag = value.tagName; | |
$(name_tag).css("color",new_color); | |
} | |
}); | |
} | |
</script> | |
<style> | |
body{ | |
background-color:#fff; | |
} | |
#vermelho{ | |
color:red; | |
font-size:50px; | |
} | |
.preto{ | |
color:#010000; | |
font-size:20px; | |
} | |
a{ | |
color:yellow; | |
font-size:20px; | |
} | |
</style> | |
</head> | |
<body onload="body_nodes()"> | |
<span id="vermelho"> vel pellentesque a,</span> | |
<br> </br> | |
<span class="preto">Maecenas commodo elit eget gravida fermentum. Quisque egest</span> | |
<a href="#"> | |
as metus a orci eleifend, quis tincidunt mauris fermentum. Fusce eget turpis a | |
</a> | |
<button onclick='change_colors("blue")'>Clique aqui para alterar as cores</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment