jquery 加载嵌入CSS文件并进行编辑以隐藏元素

af7jpaap  于 2023-10-17  发布在  jQuery
关注(0)|答案(1)|浏览(82)

我可以使用JavaScript加载embedded CSS file,然后编辑它以隐藏.embed--powered--logo类,并从弹出窗口隐藏Powered by Shoppy吗?
嵌入代码是:

<script src='https://shoppy.gg/api/embed.js'/>
<button data-shoppy-product="ID-HERE">Pay</button>

我尝试了这个CSS,但不工作:

<style type='text/css'>
.embed--powered--logo {
clip-path: polygon(0px 0px, 0px 0px, 0px 0px) !important;
-webkit-clip-path: polygon(0px 0px, 0px 0px, 0px 0px) !important;
}
</style>
mzmfm0qo

mzmfm0qo1#

我想我知道你有什么问题,你想加载一个外部的CSS文件,然后然后改变它由您的自定义文件,对吗?
如果是这样的话,你可以这样做:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Your document title</title>
    ...

    <script>
      var LinkCss = document.createElement("link");
      LinkCss.href = "path-to-your-css-file.css"; // path to the file you have that css;
      LinkCss.rel = "stylesheet"; // link type, in this case CSS
      document.head.appendChild(LinkCss); // Add to the body

      // Wait for the CSS to load, your custom css file
      LinkCss.onload = function () {
        // When the css is fully loaded

        // Get element with the class name as 'embed--powered--logo'
        var poweredLogo = document.querySelector(".embed--powered--logo");

        // Check if it's not null to prevent errors
        if (poweredLogo) {
          // Hide the element by setting its display to "none"
          poweredLogo.style.display = "none";
        }
      };
    </script>
  </head>
  <body>
    ...
    <script src="https://shoppy.gg/api/embed.js"></script>
    <button data-shoppy-product="ID-HERE">Pay</button>
    ...
  </body>
</html>

我希望这对你有帮助:)

相关问题