Question

I'm trying to use prepend() to put a text before an input text.

This is my try:

http://jsfiddle.net/sx7JW/2/

but it doesn't work..

any idea?

Javi

Was it helpful?

Solution

You don't want to use prepend, which adds the given text inside the input is makes your text appear in the input. Something like:

<input type='text'>Your text</input>

You need to use before which creates

Your Text <input type='text'/>

See this jsFiddle

You can also do something like this, this adds the text as first item for the parent of the input.

$('input').keypress(function(e) {
    if(e.keyCode == 13) {
        console.log($(this));
        $(this).parent().prepend("<p>fasf</p>");
        alert('You pressed enter!');
    }
  });

OTHER TIPS

  1. You set it to mootools not jquery
  2. What you need is before() not prepend().

http://jsfiddle.net/sx7JW/9/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top