Here's the js fiddle showing the question in action.
In the component rendering function, I render the div with the .blah class. In the componentDidMount function of the same component, I expected that I could select the .blah class and add to it like this (since the component was installed)
$('.blah').append("<h2>Appended to Blah</h2>");
However, the added content is not displayed. I also tried (also shown in the violin) to add the same, but from the parent component to the subcomponent, with the same result, and also from the subcomponent to the space of the parent component with the same result. My logic for trying the latter was to be more certain that the dom element was provided.
At the same time, I was able (in the componentDidMount function) getDOMNode and add to this
var domnode = this.getDOMNode(); $(domnode).append("<h2>Yeah!</h2>")
all the same reasons for styling CSS I would like to add to the div with the class that I know. Also, since according to docs, getDOMNode deprecated, and using replace with getDOMNode not possible to do the same thing
var reactfindDomNode = React.findDOMNode(); $(reactfindDomNode).append("<h2>doesn't work :(</h2>");
I don't think that getDOMNode or findDOMNode is the right way to do what I'm trying to do.
Question: Can I add to a specific id or class in React? Which approach should I use to accomplish what I'm trying to do ( getDOMNode , although is it deprecated?)
var Hello = React.createClass({ componentDidMount: function(){ $('.blah').append("<h2>Appended to Blah</h2>"); $('.pokey').append("<h2>Can I append into sub component?</h2>"); var domnode = this.getDOMNode(); $(domnode).append("<h2>appended to domnode but it actually deprecated so what do I use instead?</h2>") var reactfindDomNode = React.findDOMNode(); $(reactfindDomNode).append("<h2>can't append to reactfindDomNode</h2>"); }, render: function() { return ( <div class='blah'>Hi, why is the h2 not being appended here? <SubComponent/> </div> ) } }); var SubComponent = React.createClass({ componentDidMount: function(){ $('.blah').append("<h2>append to div in parent?</h2>"); }, render: function(){ return( <div class='pokey'> Hi from Pokey, the h2 from Parent component is not appended here either? </div> ) } }) React.render(<Hello name="World" />, document.getElementById('container'));