Variable taking all TAG values

Asked

Viewed 51 times

0

ma API is returning me a token. I get this value in my html in a div with the id token. Then 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 on the console it returns like this:

token value I tried with . value at the end and it returns Undefined to me on the console.log What do I need to do for him to return only the token value to me? Thank those who respond!

  • capture the value of this div? or input? places the html where the token is appearing. complete your question

1 answer

0


Div has no value attribute and therefore results in Undefined you can pick up the token in the following way:

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

in js pure

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>
<div id="token">
teqwufugjfguwef6548446grh
</div>

  • So... It looks like a solution, but you have a javascript example yourself?

  • I edited the reply added javascript snippet without jquery

  • Unfortunately it didn’t work here, is returning me null

  • You could add Aki your html and javascrip to fcilitar help

Browser other questions tagged

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