Solved

Add px value to jquery css command

Posted on 2013-06-24
3
472 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 58

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

624 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