Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery insertafter() is not working in $(this) variable

Tags:

jquery

jquery insertafter() is not working in $(this) variable.

My coding is here

<select name="input_field[]" class="selectcase">
        <option value="">Select</option>    
        <option value="input">Text</option> 
        <option value="option">Option</option>  
</select>

Script

$(this).change(function (){         
    $("<div><input type='text' name=''></div>").insertAfter($(this));           
});

I have many select tag and choose particular select tag. Using change function, I want to add textbox after select tag. I used insertAfter() function. But it is not working.

like image 357
Mukhila Asokan Avatar asked Nov 26 '25 17:11

Mukhila Asokan


1 Answers

Dont use this as id in first line, must be replaced with select :

$('select').change(function (){         
    $("<div><input type='text' name=''></div>").insertAfter($(this));           
});
like image 80
Rohit Arora Avatar answered Nov 28 '25 16:11

Rohit Arora