0

I have a variable retrieved using localstorage. On the next page I want to create a variable and add a CSS style to it before using it.

The variable in this is packageName, which works fine if I dont add the css. This is what I've tried below

var packageName = ((localStorage['chosenPackage']).css('text-transform','capitalize'));

$('.js-package-name').text('1 x ' + packageName + ' Profile');

But it returns Uncaught TypeError: localStorage.chosenPackage.css is not a function

2
  • 1
    Missing $ but even still packgeName will be a jQuery object so not really clear what you are trying to do Commented Mar 5, 2016 at 1:51
  • @charlietfl It prints out "packageName = gold" through console. What I want to do is make the first letter of "gold" Uppercase before I use it in the DOM. Commented Mar 5, 2016 at 2:05

1 Answer 1

1

localStorage only stores strings. So you're trying to apply CSS to a string. You'd want to do something like:

var packageName = localStorage.chosenPackage

$('.'+packageName).css('text-transform', 'uppercase')
  .text('1 x '+packageName+ ' Profile')
Sign up to request clarification or add additional context in comments.

2 Comments

Hey Thanks for claryifying that. At least I know why its not working. You solution doesn't work in my case because I wanted to change the string with css before I use it. I found a work around by changing when I use by adding the css then.
I can't find exactly what I wanted but this solution provides a solid work around for me. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.