简体   繁体   English

从 React 应用程序更新非 React Dom 元素的 CSS 属性

[英]Update CSS Attribute of Non-React Dom Element from React app

I'm creating a react-based app that will function within a Wordpress page.我正在创建一个基于反应的应用程序,它将 Wordpress 页面中的 function 。 The app is self-contained for the most part, but I'd like to be able to show/hide a div element on the page that is not part of the react app.该应用程序大部分是独立的,但我希望能够在页面上显示/隐藏不属于反应应用程序的 div 元素。 If I were doing this with jQuery I could just do:如果我用 jQuery 做这个,我可以这样做:

jQuery(".image_column").css("display","none");

But since I want to call this from a function at a certain point in the react app I'm getting tripped up.但是因为我想在反应应用程序的某个时刻从 function 调用它,所以我被绊倒了。 It seems like a straightforward thing to do but I'm stumped.这似乎是一件简单的事情,但我很难过。 Thanks for the help!谢谢您的帮助!

I think this is what you need:我认为这是你需要的:

document.querySelector(".image_column").style.display = "none"

This was a silly one on my part.这对我来说很愚蠢。 The answer was to add "window."答案是添加“窗口”。 Once I did that everything worked.一旦我这样做了,一切都奏效了。 I'll leave this question up in case someone else has a temporary issue of seeing the simple answer!我会留下这个问题,以防其他人暂时无法看到简单的答案!

In my case, with Wordpress, I needed to reference jQuery and not $.就我而言,对于 Wordpress,我需要引用 jQuery 而不是 $。 So it looks like:所以它看起来像:

window.jQuery(".entry-content").css("display","none");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从非反应环境中更新组件? - How to update component from non-React environment? 从非反应式jQuery HTML表单页面传递参数以响应应用程序 - Pass parameter from non-react jquery html form page to react app 有没有办法在React应用中链接未反应的html文件? - Is there a way to link non-react html files in a react app? 从非反应 class 使用反应路由器 - Using React Router from a non-react class 在生命周期方法或 Hooks 中检测页面上是否存在非反应元素 - Detect if a non-react element exists on the page in lifecycle methods or Hooks 在 React 中包装一个沉重的非 React 组件 - Wrap a heavy non-React component in React Shakapacker,Rails,React:不加载非反应的应用程序/资产 javascript - Shakapacker, Rails, React: Doesn't load up app/assets non-react javascript 非反应元素上的React-Bootstrap Popover-错误的位置和不变的错误 - React-Bootstrap Popover on non-react element - wrong position and invariant error 如何在 React 中从非 React 库中渲染 div 对象? - How do you render div objects from non-React libraries in React? 如果没有非 React DOM 父级,则无法卸载 React 门户 - 如何在删除父级之前手动卸载门户? - React portal cannot be unmounted without non-react DOM parent - how can I unmount the portal manually before removing the parent?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM