Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this jQuery .css() not work?

I have this javascript to center a span in a div:

var winWidth = $(window).width();
var winHeight = $(window).height();
var positionLeft = (winWidth/2) - 62;
var positionTop = (winHeight/2) - 32;

$('#centerMessage').ccs("position","absolute");
$('#centerMessage').ccs("top",positionTop);
$('#centerMessage').ccs("left",positionLeft);

I keep getting the error that the object does not have the method css. Any idea what is wrong?

All the HTML and CSS are at this fiddle (I am getting the exact same error there: http://jsfiddle.net/chromedude/s6WQD/

like image 355
chromedude Avatar asked Mar 16 '26 20:03

chromedude


2 Answers

you are using ccs not css in your code

$('#centerMessage').css("position","absolute");
$('#centerMessage').css("top",positionTop + 'px');  // add unit also
$('#centerMessage').css("left",positionLeft + 'px');
like image 64
Gaurav Avatar answered Mar 19 '26 09:03

Gaurav


You should add units to your values, as well:

$('#centerMessage').css("top",positionTop + "px");
like image 27
naivists Avatar answered Mar 19 '26 11:03

naivists