2

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/

11
  • 7
    ccs? thats not right... Commented Apr 19, 2011 at 16:32
  • @cthom06 O, wow thanks. I am not very smart. Commented Apr 19, 2011 at 16:33
  • When the console complains that a method doesn't exist... it usually doesn't ;) Commented Apr 19, 2011 at 16:34
  • 2
    $.fn.ccs = $.fn.css. :-) Commented Apr 19, 2011 at 16:34
  • Nice comment, chromedude. That made me laugh! Commented Apr 19, 2011 at 16:35

6 Answers 6

6

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');
Sign up to request clarification or add additional context in comments.

Comments

4

You should add units to your values, as well:

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

Comments

3

You need to be using .css, not .ccs

Comments

3

you sure you have jquery included into your page ?

.ccs => .css

Comments

3

Try:

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

Comments

0

misspelled the property:

.ccs - > .css

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.