[英]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.