Fórum Qual o erro do script? :s #551568
15/04/2016
0
<!DOCTYPE html>
<html>
<body>
<div class="example">Hello World.</div>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = document.getElementsByClassName("example");
window.alert(x);
}
</script>
</body>
</html>
Foxtery
Curtir tópico
+ 0Posts
15/04/2016
Raylan Zibel
<!DOCTYPE html>
<html>
<body>
<div class="example" id="example">Hello World.</div>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
//var x = document.getElementsByClassName("example");
var x = document.getElementById("example");
window.alert(x.innerText);
}
</script>
</body>
</html>Precisa ser pelo nome da classe?
Gostei + 0
15/04/2016
Foxtery
Gostei + 0
15/04/2016
Raylan Zibel
Gostei + 0
15/04/2016
Foxtery
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div class="example">Hello World.</div>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = $( ".example" );
window.alert(x.innerText);
}
</script>
</body>
</html>
Gostei + 0
15/04/2016
Raylan Zibel
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div class="example">Hello World.</div>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = $( ".example" );
window.alert(x.html()); // aqui
}
</script>
</body>
</html>Gostei + 0
15/04/2016
Foxtery
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)