Using Jquery, toggle a replaceWith command to switch between an input
I have a problem I cannot seem to solv开发者_开发技巧e.
I have a php and sql function that creates and populates a select drop-down. I need to be able to toggle this with a simple text input. I can use replaceWith() to get from the select drop-down to the text input but I cannot work out how to switch back to the original select drop-down.
$('.plus').click(function() {
var id = $(this).closest('li').find('select').attr('id');
$(this).closest('li').find('select').replaceWith('<input class="new_input" type="text" id="' + id + '" />');
});
So when .plus is clicked I need it to toggle between the select and input items. I am creating the new input in jquery as I need to dynamically assign the input's id. Any help is greatly appreciated!
don't remove the SELECT, just hide & disable it, and remove the ID attibute. When you need to switch back to a SELECT, hide & disable the input, remove the ID attribute and restore it to the SELECT, which you then show and enable.
精彩评论