I'm trying to call a variable function name as I've done many times before using similar code from here with
<script type="text/javascript">
$.fn.toggleHeightAndOpacity = function(show) {
$(this).stop(true,false).animate({
opacity: (show)?'show':'hide',
height: (show)?'show':'hide'
},
function(){
$(this).css('display', (show)?'auto':'none')
})
};
...
ws.onmessage = function (evt) {
var data = JSON.parse(evt.data);
if(evt.data.type = 'function'){
var parameters;
try{
parameters = JSON.parse(data.parameters);
}
catch(e)
{
parameters = data.parameters;
}
$('#'+data.id)[data.function](parameters)
}
};
but I keep getting Uncaught TypeError: Property '$.fn.toggleHeightAndOpacity' of object [object Object] is not a function
even though the JSON returned from my WebSocket server is {"function":"$.fn.toggleHeightAndOpacity","id":"container","parameters":true,"type":"function"}
.
container
exists in my html, and jQuery is loaded.
How can this be resolved?