jquery input.focus + wrap can't type in input

 <input type="text" class="form-text required" value="" size="35" id="editfiled" name="somename" maxlength="128">
 <div class="description"><p>some text</p>

$('input').focus(function () {

   $(this).wrap('<div ></div>').select('input');

and after that I can't type in this input.

I need that if input gets focus it must be highlighted inside div.


You run into a circle.

If the input gets the focus, you wrap it into the div. As this is a rebuilding of the markup, the input will lose the focus. If you click on it again, focus will be triggered again, another div will be wrapped around the input and so on.

You could try it like that:

$('input').focus(function () {      

      var _this=this;

It stores the wrapper-div as data() of the input, so if the input is already wrapped, the function would'nt do anything.

Don't forget to remove the wrapper from data() too if you somewhere remove the div wrapped around the input.

(In Firefox the selection is lost when slideToggle is finished, maybe you need another solution to show/hide the description)

It should look like this (no parameters to the .select() call):

$('input').focus(function () {  

You can test it here.

Need Your Help

Down-sample audio data to 5512 Hz PCM

c++ ios audio signal-processing core-audio

How is audio data down-sampled to 5512 Hz PCM? I have read some articles and the steps involved are decoding the audio to PCM, converting it to Mono and then downsampling it.

Should a class that provides functionality be static or singelton?

c# design-patterns static

I'm writing a C# app, and I have a class that all it dos is to provide functionality to different class I use.