jQuery Simple Example

HTML

<script src="//www.addressfinder.co.nz/assets/v2/widget.js"></script>
<input type="text" id="name" name="name"/>

CSS

body {
    padding: 5px;
}

label {
    font-weight: bold;
}

input[type=text] {
    width: 20em
}

p {
    margin: 1em 0 0;
}

JavaScript

$(document).ready(function() {
    $('#name').keyup(function(key){
        if (this.value.length >= 2 || this.value == ''){
            alert('my message'); // This works but it not what I want to do.
            // I want to have a message after my field with the error message.

            $('#name').after('<span class="error"> my message</span>');
            //This is what I try also but it repeat the message many times.

            document.getElementById("name").innerHTML = "my message";    
            // I tried this but I didn't see anything in my browser.         
       }
    });
});