I have multiple div on same id, and i want change that all div backgorund.
我有多个div在同一个id上,我想要改变所有的div backgorund。
function myfun(id) {
$('#pinsss').css({ background: "#0066ff"} );
}
this script working well to first element and others not working.
此脚本适用于第一个元素和其他不工作的元素。
4 个解决方案
#1
1
note : keep in mind, id is unique. one element can have one id and it should be different from others. instead of id, if you can use class. because , class can use for any number of elements.
注意:记住,id是唯一的。一个元素可以有一个id,并且它应该与其他元素不同。而不是id,如果可以使用类的话。因为类可以用于任意数量的元素。
#one{
width:100px;
height:100px;
margin:50px;
border:4px solid orange;
}
#two{
width:100px;
height:100px;
margin:50px;
border:8px solid red;
}
#three{
width:100px;
height:100px;
margin:50px;
border:6px solid blue;
}
.all{
background-color:pink;
}
<html>
<head>
<title></title>
</head>
<div class="all" id="one"></div>
<div class="all" id="two"></div>
<div class="all" id="three"></div>
<body>
</body>
</html>
like above code, each div has unique
id
.but same class
, if you do any changes to the class
, that will affect to all, which has same class, name. but id
is different, styles apply only for the declared id
.
与上面的代码一样,每个div都有唯一的id,但是相同的类,如果对类做任何更改,都会影响到具有相同类名的所有div。但是id是不同的,样式只适用于已声明的id。
#2
2
IDs should be unique and only one element on a page should have a given ID. Trying using a class instead.
ID应该是唯一的,页面上只有一个元素应该有一个给定的ID。
#3
0
First thing you should not use same id for all element, id should be unique to be ever element,
首先你不应该对所有元素使用相同的id, id应该是唯一的,
you should use class in this scenario, because you want to share the same behaviour for multiple element you can achieve this by using class,
你应该在这个场景中使用类,因为你想为多个元素共享相同的行为你可以通过使用类来实现,
#4
0
Try to use different Id's for each element.
尝试为每个元素使用不同的Id。
function myfun(firstId) {
$('#pinsss').css({ background: "#0066ff"} );
}
function myfun(secondId) {
$('#pinsss').css({ background: "#0066ff"} );
}
#1
1
note : keep in mind, id is unique. one element can have one id and it should be different from others. instead of id, if you can use class. because , class can use for any number of elements.
注意:记住,id是唯一的。一个元素可以有一个id,并且它应该与其他元素不同。而不是id,如果可以使用类的话。因为类可以用于任意数量的元素。
#one{
width:100px;
height:100px;
margin:50px;
border:4px solid orange;
}
#two{
width:100px;
height:100px;
margin:50px;
border:8px solid red;
}
#three{
width:100px;
height:100px;
margin:50px;
border:6px solid blue;
}
.all{
background-color:pink;
}
<html>
<head>
<title></title>
</head>
<div class="all" id="one"></div>
<div class="all" id="two"></div>
<div class="all" id="three"></div>
<body>
</body>
</html>
like above code, each div has unique
id
.but same class
, if you do any changes to the class
, that will affect to all, which has same class, name. but id
is different, styles apply only for the declared id
.
与上面的代码一样,每个div都有唯一的id,但是相同的类,如果对类做任何更改,都会影响到具有相同类名的所有div。但是id是不同的,样式只适用于已声明的id。
#2
2
IDs should be unique and only one element on a page should have a given ID. Trying using a class instead.
ID应该是唯一的,页面上只有一个元素应该有一个给定的ID。
#3
0
First thing you should not use same id for all element, id should be unique to be ever element,
首先你不应该对所有元素使用相同的id, id应该是唯一的,
you should use class in this scenario, because you want to share the same behaviour for multiple element you can achieve this by using class,
你应该在这个场景中使用类,因为你想为多个元素共享相同的行为你可以通过使用类来实现,
#4
0
Try to use different Id's for each element.
尝试为每个元素使用不同的Id。
function myfun(firstId) {
$('#pinsss').css({ background: "#0066ff"} );
}
function myfun(secondId) {
$('#pinsss').css({ background: "#0066ff"} );
}