-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery05-css.html
67 lines (58 loc) · 1.19 KB
/
jquery05-css.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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Get y Set</title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).on('ready',function(){
$('body,html').css('background','#FFF');
/* Modificar una propiedad */
$('h1').css('text-align','center');
/* Ejemplo2: para modificar varias propiedades */
var cssH1={
'text-align':'center',
'color':'red'
}
$('h1').css(cssH1);
/* también podríamos haber puesto directamente el objeto Json
dentro del método css*/
/* Ejemplo3: condiciones */
var bgItem2 = $('#item2').css('background-color');
var cItem2 = $('#item2').css('color');
if (bgItem2==cItem2)
console.log('tienen el mismo color'+bgItem2);
});
</script>
<style>
body,html
{
background: #CCC;
color:red;
font-family: Arial;
margin:0;
padding: 0;
}
#item1
{
background: #F6F6F6;
height:50px;
margin:5% auto;
width:300px;
}
#item2
{
display: block;
background: #000;
height:50px;
margin:5% auto;
width:300px;
}
</style>
</head>
<body>
<h1>Método CSS</h1>
<div id="item1">Elemento 1</div>
<div id="item2">Elemento 2</div>
</body>
</html>