I want to disable the button once I have pressed it on my page. Then when I go into the favourites page and delete the item from there, the button should reappear but I do not know how to do it.
Could I get some help please?
$(document).ready( function() {
$("#add_btn").on("tap", function(){
var propName = $("#propName").text();
var propPrice = $("#propPrice").text();
var pageURL = $(location).attr("href");
localStorage.setItem("propName", propName);
localStorage.setItem("propPrice", propPrice);
localStorage.setItem("prop", pageURL);
$('#pFave').html("Property added to Favourites");
$("#popupFave").popup("open", "reposition", 'positionTo: window');
});
var propLength = window.localStorage.length;
console.log(propLength);
if(propLength !=0){
var hName = localStorage.getItem("propName");
var hPrice = localStorage.getItem("propPrice");
var url = localStorage.getItem("prop");
var list = "<li><a href='"+ url +"' data-ajax='false'>" +hName +"<br> "+hPrice + "</a><button id='remove' class='ui-btn ui-corner-all'>Delete</button></li>";
$('#listProperties').append(list).listview('refresh');
$('#remove').on("tap", function(){
localStorage.removeItem("propName");
localStorage.removeItem("propPrice");
localStorage.removeItem("prop");
window.location.reload();
});
} else {
var list = "<li data-icon='false'><a href='#' data-ajax='false'>No Properties Saved</a></li>";
$('#listProperties').append(list).listview('refresh');
}
});
<div data-role="popup" id="popupFave" data-overlay-theme="a" data-theme="a" data-dismissible="false" style="max-width:300px;">
<div role="main" class="ui-content">
<h3 id='pFave'> </h3>
<a href="#" class="ui-btn ui-corner-all " data-rel="back">Ok</a>
</div>
</div>
<button id="add_btn" data-icon="star">Add to favourites</button>
To disable the button: $("#add_btn").attr("disabled", true);
To enable the button you could to $('#add_btn').attr("disabled", false);
or $('#add_btn').removeAttr("disabled");