I'm learning ReactJs and really like it. I wanted to ask if we can render virtual DOM to document by class name.
React.render(
<CommentBox url="data/comments.json" pollInterval={2000} />,
document.getElementById('class')
);
I tried to pass
getElementByClassName('class')
as second argument to react's render method and it doesn't work. Does React only render DOM to nodes with ID's only or is there's a workaround to use nodes with classes too?
It seems you have used a wrong method.
Probably you should use getElementsByClassName
instead of getElementByClassName
. And DO NOT forget getElementsByClassName
returns an array-like obj HTMLCollection, so picking the first element is necessary.
React.render(
<CommentBox url="data/comments.json" pollInterval={2000} />,
document.getElementsByClassName('className')[0]
);
For more infomation, check out the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With