Give help. Get help.

  • # August 9, 2012 at 6:27 pm

    Hey, so I’m having trouble understanding why a JQuery variable is retuning undefined. This is what I have in my HTML:

    < !doctype html>



    #box {
    background-color: #FF0000;
    width: 200px;
    height: 100px;

    and Javascript:

    var cssWidth = $('').css('width');


    However, when I reload the page, the alert that gets triggered comes back saying “undefined” I’ve checked all the syntax out and it looks like everything is all good. Anyone see where the problem is? This is running on my localhost, but I do have JQuery called in my HTML, so it should work. I’m also pretty new at this stuff, so any help would be appreciated.

    # August 9, 2012 at 6:44 pm
    var cssWidth = $('#box').css('width');

    no dot in the selector

    # August 10, 2012 at 12:50 am

    Ok, fixed that, but it’s still returning as undefined. This is what the javascript looks like now, but the HTML and CSS are the same as above.

    var cssWidth = $('#box').css('width');

    # August 10, 2012 at 12:58 am

    fixed it. apparently this is the wrong way to do it:

    < !doctype html>


    and this is the RIGHT way:

    < !doctype html>


    if you do do it the first way, by loading the scripts in the head, you need to call

    //Code goes here.

    in your script file.

    # August 10, 2012 at 6:55 pm

    Good to know. Thank you! :D

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.