String Length function not working properly

I have a function that’s supposed to check the length of a Tweet input box and make display a message depending on weather the max characters are exceeded or not. But when i run it, the if else loop only runs the “else” part no matter how many characters have been typed.

My Code:


function checkTweet() {
	var maxLength = 140;
	var button = document.getElementById('submit');
	var tweetLength = document.getElementById("name");
	
	button.onclick = function () {
		if (tweetLength.length <= maxLength) {
			alert("Tweet Submitted");
		} else {
			alert("You have to many characters!");
		}
	};
}

if an element with the id ‘name’ is an input field, you probably want to read the length of its value, the text it contains.

Thank You! That did the trick.