Solved

Add px value to jquery css command

Posted on 2013-06-24
3
463 Views
Last Modified: 2013-06-24
Hi,

I am trying to add variables to the transform command in CSS with jquery but it doesnt work, any ideas?

My code is

 $x = $(this).attr("cx")+'px';
 $y = $(this).attr("cy")+'px';
      $(this).css('transform', "translate($x,$y) scale(2)"); });

$x and $y do get values.

Thanks
0
Comment
Question by:coolispaul
3 Comments
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39270901
You are putting '$' in front of your vars - this is JQuery not PHP

Try this

var x = $(this).attr("cx")+'px';
var y = $(this).attr("cy")+'px';
$(this).css('transform', "translate(x,y) scale(2)"); });
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39271291
jQuery doesn't replace variables in strings the same way that PHP does. You need to concatenate the translate argument properly:

$x = $(this).attr("cx")+'px';
$y = $(this).attr("cy")+'px';
$(this).css('transform', "translate(" + $x + "," + $y + ") scale(2)");

Open in new window

The $ before the variable name is OK, although not very common!
0
 

Author Comment

by:coolispaul
ID: 39271482
thanks yes that works..
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question