开发者

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/


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');


You should add units to your values, as well:

$('#centerMessage').css("top",positionTop + "px");


You need to be using .css, not .ccs


you sure you have jquery included into your page ?

.ccs => .css


Try:

$('#centerMessage').css("top",positionTop + "px");
$('#centerMessage').css("left",positionLeft + "px");


misspelled the property:

.ccs - > .css
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜