jQuery - capture element and assign to variable
I'm trying to find out whether it's possible to assign lets say the entire tag with the specific class to a variable and then use it to replace another element.
The scenario is very simple - you click on the button in the form, button is assigned to variable (the entire button not just attribute of it or value - the html element), we replace the button with some other element (say Processing.. message or animated gif) and once ajax call is finished and was unsuccessful, we replace the 'Processing..' element back with our button.
The only way I would currently do it would be to wrap the trigger (button) with some开发者_高级运维 div and use html() to get the button and replace it with the new content - then reverse it, but we're left with the wrapping div.
Any better ideas?
You can use jQuery .clone()
- it completely clones the element including the class names and such. jQuery Api
why not just hide them?
$("#button").hide();
$("#loading").show();
精彩评论