0

I'm trying to get the value of an input, and create an element with the value text in it. I don't know why this isn't working.

(And, yes! I called the function. Just didn't post the jQuery enter key code.)

<input type="text" id="user-input"/>

 function submitUserMessage(){
    var message = document.getElementById("user-input");

    if(message.value){
        var userMessageElement = document.createElement("span");
        var userMessageElementText = userMessageElement.createTextNode(message.value);
        userMessageElement.appendChild(userMessageElementText);
        userMessageElement.className = "umsg";
        userMessageElement.style.backgroundColor = "#fff";
        document.body.appendChild(userMessageElement);
    }
}
1
  • 1
    So you're saying you're using jQuery ? Commented Jul 20, 2013 at 6:29

1 Answer 1

1

you must call document.createTextNode() instead of userMessageElement.createTextNode()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.