Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

TypeError: this.box.css is not a function

Junior Spellweaver
Joined
Aug 15, 2011
Messages
167
Reaction score
15
Hello people,

I have a problem. I am trying to run some code but I get an error in my console.

This is my code:

PHP:
var Amber = {
	Notification: function (type) {
		this.message = null;
		this.box = null;

		switch(type) {
			case 'bad':
				this.box = '<div class="Notification bad><i class="icon-notok"></i>' + this.message + '</div>';

			break;

			case 'good':
				this.box = '<div class="Notification good><i class="icon-ok"></i>' + this.message + '</div>';
			break;

			case 'informative':
				this.box = '<div class="Notification informative><i class="icon-informative"></i>' + this.message + '</div>';
			break;

			case 'warning':
				this.box = '<div class="Notification warning><i class="icon-warning"></i>' + this.message + '</div>';
			break;
		}

		this.SetMessage = function (message) {
			this.message = message;
			return this;
		}

		this.Show = function () {
			this.box.appendTo(document.body);
		}
	}
}

The error:
PHP:
TypeError: this.box.appendTo is not a function

I am calling the function with:

PHP:
new Amber.Notification.SetMessage('Some message').Show();

I also would like to add sme CSS to
PHP:
this.box
but that causes the same error. Does anyone know why this is happening?
Thanks in advance!
 
Junior Spellweaver
Joined
Aug 15, 2011
Messages
167
Reaction score
15
It'd be nice if you reported what the problem was and how you fixed it, as well. :)
AppendTo is a jQuery function wich has to be applied to a jQuery selector:
PHP:
$('')
.
It wasn't working because I set
PHP:
'<div class="Notification warning><i class="icon-warning"></i>' + this.message + '</div>'
as a string and not as a selector (which is quite stupid, to be honest :S).
 
Back
Top