comSaaxov
comSaaxov

Reputation: 73

localStorage and jQuery (no work css)

I'm doing the first two pages of received data from the form and stores it in localStorage:

<form id="myForm" method="post">
        font-size px: <input id="fontsize" type="text" name="fontsize" />
</form>


<script type="text/javascript">
  var inpX = document.getElementById('fontsize');
  var x = parseFloat(inpX.value);
  localStorage.setItem('inpX', x);

on the second page write the code jquery increases the font:

$(document).ready(function(){
 var fontsX = localStorage.getItem('inpX');
 $("#info").css('font-size':'fontsX +'px'');
});

but nothing happens. what am I doing wrong?

Upvotes: 1

Views: 86

Answers (2)

dfsq
dfsq

Reputation: 193261

Colon is used for object notation (when you pass an object of properties). So one more version to set css property:

$("#info").css({'font-size': fontsX + 'px'});

or even shorter

$("#info").css({fontSize: fontsX + 'px'});

since jQuery will normalize snake-case names to cameCase.

Upvotes: 2

Arun P Johny
Arun P Johny

Reputation: 388316

You have syntax issues, you need to pass the css property and value as 2 arguments or pass a object

$("#info").css('font-size', fontsX +'px');

Upvotes: 1

Related Questions