DELETE AN OBJECT USING THE INDEXEDDB API

You can delete an object from an IndexedDB object store using the same basic code used to get() it by its key path; however, the get() example earlier in this chapter was a read-only task, and this is a read-write task:

function deleteObjectById(id) {
   var transaction =
 db.transaction(objectStore, IDBTransaction READ_WRITE);   var store = transaction.
 objectStore(objectStore);
   var request = store.delete(id);
   request.onsuccess = function(event) {
     // Update the web page
   };
  request.onerror = function(event) {...};
 }

Only the object with a key path value of id is deleted. The process to delete an object may not be instantaneous. Remember that the IndexedDB API runs asynchronously. Therefore, only after you ...

Get HTML5: Your visual blueprint™ for designing rich web pages and applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.