Search code examples
prototypejsselector

prototype selector returns object


so I have a div:

<div id="divId">some content in here</div>

And I want to get the content of this div, so I do what I always do:

<script type="text/javascript">
    //<![CDATA[
    Event.observe(window, 'load', function() {
        var divContent = $('divId');
        console.log(divContent);
    });
    //]]>
</script>

But instead of having the content of the div logged out in firebug, I get [object HTMLDivElement].
What am I missing?

nb: protoype library is loaded in the head of my page.


Solution

  • well, I was missing .innerHTML:

    <div id="divId">some content in here</div>
    

    And I want to get the content of this div, so I do what I always do:

    <script type="text/javascript">
        //<![CDATA[
        Event.observe(window, 'load', function() {
            var divContent = $('divId').innerHTML;
            console.log(divContent);
        });
        //]]>
    </script>