How to reset DOM after manipulation?

前端 未结 3 1598
心在旅途
心在旅途 2021-01-20 03:50

My page contains some small wizard which I built using jQuery.

I would like to offer the user to restart/reset the wizard and start it from the beginning level.

3条回答
  •  后悔当初
    2021-01-20 04:01

    One way to achieve this would be to clone() the wizard's element tree in its initial state and store it in a global variable or in the document's data:

    $(document).data("initialWizard", $("#yourWizard").clone(true));
    

    (Note that passing true to clone() also clones element data and event handlers, which might prove handy in your case.)

    Then, when you want to restore the wizard to its original state, you can do:

    $(document).data("initialWizard").replaceAll("#yourWizard");
    

提交回复
热议问题