-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathej4-anadir-clases.html
75 lines (71 loc) · 1.92 KB
/
ej4-anadir-clases.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test jquery</title>
<style>
div {
color: #fff;
padding: 10px;
width: 190px;
text-align: center;
background-color: #333;
}
.estilohover {
background-color: green;
}
.grande{
font-size: 2em;
}
.rojo{
color: red;
}
</style>
</head>
<body>
<h1>add class y remove class</h1>
<p>
<input type="checkbox" id="checkb"> Poner grande
</p>
<div id="elemento">elemento</div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ut iure ipsam magnam culpa, in totam distinctio dolorem sint maxime, obcaecati dolore enim, quos cupiditate libero. Reiciendis esse, numquam inventore distinctio.</p>
<a href="#">Hover al otro elemento</a>
<p>
<span id="alerta">alerta:</span> <b>otro</b> <input type="checkbox" class="micheck">
</p>
<p>
<span id="cuidado">cuidado:</span> <b>otro</b> <input type="checkbox" class="micheck">
</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('a').hover(
function() {
$('#elemento').addClass('estilohover');
},
function() {
$('#elemento').removeClass('estilohover');
}
);
$('#checkb').on('click', function() {
console.log(this);
if($(this).prop('checked')) {
$('#elemento').addClass('grande');
} else {
$('#elemento').removeClass('grande');
}
});
$('.micheck').on('click', function() {
var checado = $(this).prop('checked');
if(checado){
$(this).siblings('span').addClass('rojo');
//$('#alerta').addClass('rojo');
} else {
$(this).siblings('span').removeClass('rojo');
//$('#alerta').removeClass('rojo');
}
});
});
</script>
</body>
</html>