How to take the value of a div and show in javascript?

Asked

Viewed 3,988 times

0

The method ". getElementById('value'). value" shows the value of div as null

<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>

<script>
    $(document).ready(function ()
    {
        var data     = [document.getElementById('valor').value];
        var tooltips = [];
        //[2.59,2.60,2.40,2.67,1.78];

        // Create the tooltips
        for (var i=0; i<data.length; i+=1) {
            tooltips[i] = '1 USD = ' + String(data[i] + ' Reais')
        }

        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();

    })
</script>

<div id="valor"></div>
<div id="label"></div>

  • javascript-preferred

1 answer

3


value property refers to inputs and selects.

in this case you need to get the internal HTML of the DIV.

.getElementById('valor').innerHTML
  • Or, since his code uses jQuery, $('#valor').html().

  • I have already placed of the two geitos sitados to top, but still does not show the values

  • if it is placed the values [2.59,2.60,2.40,2.67,1.78] straight in the statement of the date appears certificate but can not do so, I have to take the div !!

  • @nardo_wizard, this div initially comes nothing, how are values loaded? and where?

  • json.class.js file

  • could open the console and make a console.log($('#valor').html());?

  • How to pass an array from div to variable ??

  • The div’s Html is a string, in this case you need to do a JSON.parse. Then do the following JSON.parse($("#value"). val());

  • where I can put JSON.parse($("#value"). val()); ?

Show 4 more comments

Browser other questions tagged

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