Reputation: 3506
<input id="email" name="email" type="text" value="[email protected]">
How do I get value of id=email and print it out to my console or anywhere for testing purposes ?
I tried, but no luck :(
<script type="text/javascript">
document.getElementById('email').innerText;
</script>
Upvotes: 4
Views: 93839
Reputation: 23
let inputId = document.querySelector("#email");
console.log(inputId.value);
Upvotes: 0
Reputation: 367
In the Chrome dev tools console drop the .value:
document.getElementById('#id')
Upvotes: 0
Reputation: 2546
There are two types of elements
.innerHTML
or .html()
in jquery like div's span's etc.value
or .val()
in jquery, like input types etcall you need o do is
console.log($('#email').val()) //jquery
or
console.log(document.getElementById('email').value); // javascript
Upvotes: 6
Reputation: 1114
Without jQuery:
console.log(document.getElementById('email').value);
Upvotes: 2
Reputation: 730
this will 'print' the entire object to the console
console.log("input[id='email'] - %o", document.getElementById('email'));
Upvotes: 1
Reputation: 965
Try an alert...
var email = $("#email").val();
alert(email);
Upvotes: 1