Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975192
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:39:20+00:00 2026-05-20T04:39:20+00:00

I’m trying to implement localStorage into one of my projects, but I’m having a

  • 0

I’m trying to implement localStorage into one of my projects, but I’m having a problem because this portion of the code breaks my jQuery ui-layout.

function $(id) {
  return document.getElementById(id);
}

In order to make the layout work, I have to add a $:

$(document).ready(function($) {

Being that I don’t know how to write javascript or jquery, I can only implement it, can the code below be written in a way that I can avoid using the “function $(id)” part and the “$”?

Here is the code in its entirety:

// return value - this the prob?
function $(id) {
  return document.getElementById(id);
}

// write data to the local storage
function writeLocal() {
  var key = $('lsKey').value;
  var data = $('html').value;
  localStorage.setItem(key, data);
  updateItemsList();
}

// remove the item from localStorage
function deleteLocal(keyName) {
  localStorage.removeItem(keyName);
  updateItemsList();
}

// read the actual data for the key from localStorage
function readLocal(keyName) {
  $('lsKey').value = keyName;
  $('html').value = localStorage.getItem(keyName);
}

// allow retrieval of localStorage items
function updateItemsList() {  
  var items = localStorage.length;  
  var s = '<p>Saved Items</p>';
  s+= '<ul>';  
  for (var i=0; i<items; i++) {  
    var keyName = localStorage.key(i);
    s+= '<li class="lsdLI">' + 
        '<div style="float:right;">' + 
        '<input onClick="readLocal(\''+keyName+'\');"/>'+ 
        '<input onClick="deleteLocal(\''+keyName+'\');"/>'+
        '</div>'+
        '<b>'+keyName+'</b>' +
        '</li>';
  }

  $('lsValues').innerHTML = s + '</ul>';
}

// start by loading up whatever is persistant in localStorage

function load() {  
updateItemsList(); 
}  
window.onload = load; 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:39:21+00:00Added an answer on May 20, 2026 at 4:39 am

    So it sounds like you are using jquery UI and it’s causing a conflict. Easiest thing to do might just be renaming the $ convenience function you are using…

    // return value - this the prob?
    function $$(id) {
      return document.getElementById(id);
    }
    
    // write data to the local storage
    function writeLocal() {
      var key = $$('lsKey').value;
      var data = $$('html').value;
      localStorage.setItem(key, data);
      updateItemsList();
    }
    
    // remove the item from localStorage
    function deleteLocal(keyName) {
      localStorage.removeItem(keyName);
      updateItemsList();
    }
    
    // read the actual data for the key from localStorage
    function readLocal(keyName) {
      $$('lsKey').value = keyName;
      $$('html').value = localStorage.getItem(keyName);
    }
    
    // allow retrieval of localStorage items
    function updateItemsList() {  
      var items = localStorage.length;  
      var s = '<p>Saved Items</p>';
      s+= '<ul>';  
      for (var i=0; i<items; i++) {  
        var keyName = localStorage.key(i);
        s+= '<li class="lsdLI">' + 
            '<div style="float:right;">' + 
            '<input onClick="readLocal(\''+keyName+'\');"/>'+ 
            '<input onClick="deleteLocal(\''+keyName+'\');"/>'+
            '</div>'+
            '<b>'+keyName+'</b>' +
            '</li>';
      }
    
      $$('lsValues').innerHTML = s + '';
    }
    
    // start by loading up whatever is persistant in localStorage
    
    function load() {  
    updateItemsList(); 
    }  
    window.onload = load;   
    

    It wouldn’t be hard to convert what you have into jQuery either, but simply grabbing the first item out of each jQuery object.

    // write data to the local storage
    function writeLocal() {
      var key = $('lsKey')[0].value;
      var data = $('html')[0].value;
      localStorage.setItem(key, data);
      updateItemsList();
    }
    
    // remove the item from localStorage
    function deleteLocal(keyName) {
      localStorage.removeItem(keyName);
      updateItemsList();
    }
    
    // read the actual data for the key from localStorage
    function readLocal(keyName) {
      $('lsKey')[0].value = keyName;
      $('html')[0].value = localStorage.getItem(keyName);
    }
    
    // allow retrieval of localStorage items
    function updateItemsList() {  
      var items = localStorage.length;  
      var s = '<p>Saved Items</p>';
      s+= '<ul>';  
      for (var i=0; i<items; i++) {  
        var keyName = localStorage.key(i);
        s+= '<li class="lsdLI">' + 
            '<div style="float:right;">' + 
            '<input onClick="readLocal(\''+keyName+'\');"/>'+ 
            '<input onClick="deleteLocal(\''+keyName+'\');"/>'+
            '</div>'+
            '<b>'+keyName+'</b>' +
            '</li>';
      }
    
      $('lsValues')[0].innerHTML = s + '';
    }
    
    // start by loading up whatever is persistant in localStorage
    
    function load() {  
    updateItemsList(); 
    }  
    window.onload = load;   
    

    Beyond those two options, you’d be looking at changing your code a bit more to truly do things the jQuery way. Instead of $(‘lsKey’).value it would be $(‘lsKey’).val(), etc. You’d have to update your code to use all the jQuery methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.