如何使用 jQuery 修改 CSS 变量 [英] How can I modify a CSS variable using jQuery

查看:85
本文介绍了如何使用 jQuery 修改 CSS 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 CSS,其中设置了一个变量.我知道如何使用普通 Javascript 更改变量的值.我需要使用 jQuery 做同样的事情.

I have a CSS with a variable set in it. I know how to change the value for the variable using plain Javascript. I need to do the same using jQuery.

这是我的代码...

<style>
  :root{
    --board-bg-color:#7DD0D6;
  }
<style>

要在纯Javascript中更改--board-bg-color"的值,我可以使用

To change the value of "--board-bg-color" in plain Javascript, I can use

document.body.style.setProperty("--board-bg-color", "#"+Color);

我需要知道 jQuery 中是否有等价物.

I need to know if there is an equivalent in jQuery.

我曾尝试将 css 函数用于正文和文档,但它不起作用

I have tried using the css function for body and document, but it doesn't work

jQuery("body").css("--board-bg-color","#"+Color);

推荐答案

$("body").css("--board-bg-color","#"+Color);

这篇关于如何使用 jQuery 修改 CSS 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆