Search code examples
javascriptreactjsjsfiddle

JSFiddle react Target Container is not DOM element


In the following jsfiddle page I am trying to run some React example from one book:

I am new to react and JSFiddle and I do not understand what I have to change to the simple example work. I have read in another post with similar problem that the <script> must be the last line inside the <body> tag. But I am not importing the React scripts "manually", I am using the JSfiddle resources.

What is the difference in JSFiddle between importing the script files through <script> tag and use the Resource options ? and there is one third alternative that is to choose in the combobox the React library where we put js code to.


Solution

  • You are using document.getElementById('react-container') but you are using a class: <div class="react-container"></div>

    Change your code to:

    <div id="react-container"></div>
    

    For your next question on SO, please post your full question so the SO question is not dependent on JSFiddle

    EDIT: @NightRyder updated the fiddle: https://jsfiddle.net/n5u2wwjg/9029/