Variable taking all values from TAG

0

The API is returning me a token. I get this value in my html in a div with the id token. So I create a variable in my javascript to capture the value of this div, ie

var variavel = document.querySelector("#token");

And when I try to print to the console it returns like this:

token value I tried with the .value at the end and it returns me undefined in console.log What do I have to do to get the value of the token back? Grateful to whom to respond!

    
asked by anonymous 01.02.2018 / 14:52

1 answer

0

Div has no value attribute and therefore results in undefined You can get the token as follows:

console.log($('#token').text()) 

in pure js

var variavel = document.getElementById("token");
console.log(variavel.innerHTML)

ex:

console.log($('#token').text())
var variavel = document.getElementById("token");
console.log(variavel.innerHTML)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="token">
teqwufugjfguwef6548446grh
</div>
    
01.02.2018 / 15:00