Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Saving variables in Javascript

Featured Replies

Hi!

 

To begin with explaining my problem, I'l just show you some code:

 

function moveLeft(id)
{
  e = document.getElementById(id).style.right;

  if (e.runOnce || 1)
  {
     e.variable1=1;
     e.variable2=1;
     e.variable3=1;
     e.runOnce=1;
  }

  (some code that requires the saved variables next time this function is run)
}

 

As you see, I saved some variables inside an element in this code. This is useful sometimes, but can I save variables in a similar way, in other things than HTML elements? Like, creating an object in Javascript or something. It's not allways wery handy to create a new HTML element each time I want a place to save variables.

 

 

PS: I am pretty new to HTML and Javascript, so please excuse me if I've got some words or names wrong here :unsure:

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.