Currently I'm having this code:
<div id="groups">
<select multiple="multiple" id="availableGroups" name="availableGroups">
<option >Opt 1</option>
<option >Opt 2</option>
</select>
</div>
The "select"
element has a click event listener which attach to it.
What I'm to do is to change the $('div#groups')
content with <p>
element when the user click next button, so I do like this:
var $groupContent=$('div#groups').children(); //save the content
$('div#groups').html($("<p>").append("Opt 1"))
And if the user click the prev button,I will restore the "select"
element like this:
$('div#groups').append($groupContent);
The problem is the click event listener also has been remove when I'm using .html()
as stated on this question
So the question is,is there a workaround I can implement same action like .html()
without removing the event listener?