Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 动态添加CSS_Jquery_Css - Fatal编程技术网

Jquery 动态添加CSS

Jquery 动态添加CSS,jquery,css,Jquery,Css,我尝试了以下JQuery方法来动态替换CSS值,但它不起作用。知道哪一部分错了吗 在我的html中: <div class="svg"> <button class="type_1"></button> </div> 我当前的方法不起作用: $('.svg .type_' + list.id).css({ stroke: list.hex_color, fill: list.hex_color });

我尝试了以下JQuery方法来动态替换CSS值,但它不起作用。知道哪一部分错了吗

在我的html中:

<div class="svg">
     <button class="type_1"></button>
</div>
我当前的方法不起作用:

 $('.svg .type_' + list.id).css({
        stroke: list.hex_color,
        fill: list.hex_color
 });

如果存在连接问题,则必须将css用引号括起来

$('.svg .type_' + list.id).css({
        'stroke': list.hex_color,
        'fill': list.hex_color
 });

svg svg?尽管您的div具有svg类,但不应应用CSS,因为它是针对svg的element@phuzi我只想用动态添加的css替换当前固定的css svg.type_1{rgb…},只需删除点:$'.svg.type_'+list.id→ ` $'svg.type_'+list.id`。我尝试了这个方法,它不起作用,我如何检查这个动态添加的CSS是否在那个网页上提供?我想看看它是否覆盖了最初的CSS
$('.svg .type_' + list.id).css({
        'stroke': list.hex_color,
        'fill': list.hex_color
 });