Function not defined

Hey there,

I am getting this error “Uncaught ReferenceError: streamWidth is not defined” when trying to call the function below and it’s driving me cray cray. Appreciate any help. Thank you.

$(function streamWidth() {
var screenWidth = $( document ).width() - 40;
var numOfStreams = 3;
var streamWidth = screenWidth/numOfStreams;
$(‘.stream-container’).css(“width”, ‘streamWidth’);
});
$(streamWidth);

It’s the last line giving you problems.

$(streamWidth);

It has no access to the context of the $(…) section above it and the functions within it.

If you just want the code to work, get rid of the last line and streamWidth function name, leaving just the function there.

$(function () {
    // code in here
});

which is jQuery’s ready handler

Looks to me like you just want something simpler like this:

var screenWidth = $(document).width() - 40;
var numOfStreams = 3;
var streamWidth = screenWidth/numOfStreams;
$('.stream-container').css('width', streamWidth + 'px');

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.