Damian
Damian

Reputation: 608

Unexpected string in JS with CSS

I write small page and in this code I have error. I want to use this way because Isotope doesn't read the width and height from styles in HTML tags.

var winw = $(window).width();
var plmt_w = winw / 10;
var plmt_h = plmt_w;

var css = '.plmt { width:' plmt_w '; height:' plmt_h ';}',
.....

Upvotes: 0

Views: 133

Answers (3)

Ingmars
Ingmars

Reputation: 998

As ajm and Amit Joki said, you need + operators to concatenate strings.

But, since $(window).width() returns an unitless value, you need to add 'px' for it to be a valid css string:

var css = '.plmt { width:' + plmt_w + 'px; height:' + plmt_h + 'px;}',

Upvotes: 2

Amit Joki
Amit Joki

Reputation: 59272

Use + operator to join the strings:

var css = '.plmt { width:' + plmt_w + '; height:' + plmt_h + ';}';

Upvotes: 1

ajm
ajm

Reputation: 20105

You need to use the + operator to concatenate strings:

var css = '.plmt { width:' + plmt_w + '; height:' + plmt_h + ';}',

Upvotes: 0

Related Questions