jQuery: trying to use prepend()
Question
I'm trying to use prepend() to put a text before an input text.
This is my try:
but it doesn't work..
any idea?
Javi
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
- You set it to mootools not jquery
- What you need is before() not prepend().
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow