How to show objectHTMLDivElement"?

Asked

Viewed 58 times

0

I tried to show some values that are in a div with a document.getElementById("valor"). I used command alert(); to show what would bring and showed in the window objectHTMLDivElement how can I show this ?

Javascript

$(document).ready(function () {

    var x = document.getElementById("valor");
    var text = "";
    alert(x);

    var data = [text];
    var tooltips = [];

    var line = new RGraph.Line({
        id: 'cvs',
        data: data,
        options: {
            tooltips: {
                self: tooltips,
                highlight: false
            },
            colors: ['#058DC7'],
            filled: true,
            fillstyle: 'rgba(229,243,249,0.5)',
            tickmarks: 'filledcircle',
            background: {
                grid: {
                    vlines: false,
                    border: false,
                    autofit: {
                        numhlines: 10
                    }
                }
            },
            shadow: false,
            linewidth: 3,
            gutter: {
                left: 50,
                right: 20
            },
            numxticks: 0,
            ylabels: {
                count: 5
            },
            axis: {
                color: '#aaa'
            },
            text: {
                color: '#aaa'
            },
            labels: ['21/01', '22/01', '23/01', '24/01', '25/01']
        }
    })

    RGraph.ISOLD ? line.draw() : line.trace2();

})

HTML

<html>

    <head>
        <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
        <script src="/sistema/jquery/plugins/RGraph/libraries/RGraph.common.core.js"></script>
        <script src="/sistema/jquery/plugins/RGraph/libraries/RGraph.common.dynamic.js"></script>
        <script src="/sistema/jquery/plugins/RGraph/libraries/RGraph.common.tooltips.js"></script>
        <script src="/sistema/jquery/plugins/RGraph/libraries/RGraph.line.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript" src="http://www.google.com/jsapi"></script>
        <script type="text/javascript">
            google.load("jquery", "1.3.2", {
                uncompressed: true
            });
        </script>
        <script type="text/javascript" src="json.class.js"></script>
        <!--[if lt IE 9]>
            <script src="../excanvas/excanvas.js"></script>
        <![endif]-->
        <p style="margin-left:50em;">
            <title>Cotação USD x BRL</title>
        </p>
        <meta name="robots" content="noindex,nofollow" />
        <meta name="Descrição" content="Cotação do Dolar de Acordo com o Real" />
    </head>

    <body>
         <h2></h2>

        <canvas id="cvs" width="900" height="300">[No canvas support]</canvas>
        <div id="valor"></div>
        <div id="label"></div>
    </body>

</html>

1 answer

1

When you use document.getElementById("valor") This will give you a reference to the DOM Object with the id valor. This object has several properties, one of which I think is what you want is the .innerHTML.

So if you use document.getElementById("valor").innerHTML That will give you the HTML that’s inside that div.

Using your code would be:

$(document).ready(function () {
    var data = document.getElementById("valor").innerHTML;
    alert(data); // dá uma string com o que tiveres dentro dessa div
});

If you want the contents of div without HTML tags you can use .textContent.

  • I changed the file more now the "Alert();" comes empty

  • @nardo_wizard in the example you put in the question the div is empty... You have some content in the DIV?

  • Numbers of a server JSON file are being displayed for the html page containing the div. In the browser appears like this ex: "2.51,2.56,2.87,2.89,2.94", but when I show it comes empty pq ?

  • @nardo_wizard puts in the question all the code you have and then I can explain better. Probably the div is still empty at the time of Alert but is filled right away. Also explain the functionality of the page so we can understand it better so we can help you better too.

  • The page makes a graph. When the values of Div "value" are placed in the "date" variable the graph will form (OBS: This graph is on a server.). I have tried using xmlhttp, Jquery to try to put the values in the variable but can not help me please !.

  • @nardo_warlock says above that "Numbers of a JSON file are being evinced from the server to the html page that contains the div"... where? don’t see this code in your question? via AJAX? or via PHP?

  • is via AJAX. How can I get the data with jQuery.getJSON() or any other mode ?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.