I have a problem with duplicates ajax content in jquery mobile (knockout). The problem start when I call back button to start form and when I calling again all process. Example code:
<div data-role="header" data-theme="c">
<a data-bind="click: headerBackBtn" data-role="button">Back</a>
<h1>
Header title
</h1>
</div>
<div data-role="content">
<form id="form" name="form" data-bind="visible: form">
<label for="name">Name:</label>
<input type="search" name="name" id="name"/>
<button data-bind="click: toFirstContent" data-icon="search">Search</button>
</form>
<!-- first content -->
<div class="div-1" id="div-1" data-bind="visible: div-1">
<a data-bind="click: toSecondContent">
Link
</a>
</div>
<!-- second content -->
<div class="div-2" id="div-2" data-bind="visible: div-2">
Text
</div>
</div>
<div data-role="footer" data-theme="c">
<h4>footer</h4>
</div>
self.headerBackBtn = function () {
if (self.div-2()) {
self.div-2(false);
self.div-1(true);
return;
}
if (self.div-1()) {
self.div-1(false);
self.form(true);
return;
}
};
Solution is http://api.jquery.com/remove/. For every element I put class="removeItem" and then call $(".removeItem").remove(), before I call function for getting new elements...