Why the heck its not working?

+1 William Frost · April 8, 2015
Sorry for that title, but I need help :(

<script>

_("H").appendText("Hi");

</script>
and <div id="H">g</div>
Its just not appending it to the div, and like "crashing" everything else. Have no idea why.
when the 'appendText' is from another file(<script src="underline.js"></script>):


function _(id) {

   // About object is returned if there is no 'id' parameter
   var about = {
      Version: 0.3,
      Author: "The Frostinator",
      Created: "July 2014",
      Updated: "March 2015"
   };

   if (id) {

      // Avoid clobbering the window scope:
      // return a new _ object if we're in the wrong scope
      if (window === this) {
         return new _(id);
      }

      // We're in the correct object scope:
      // Init our element object and return the object
      this.e = document.getElementById(id);
      return this;
   } else {
      // No 'id' parameter was given, return the 'about' object
      return about;
   }
};

/* _ Prototype Functions
============================*/
_.prototype = {
   hide: function () {
      this.e.style.display = 'none';
      return this;
   },

   show: function () {
      this.e.style.display = 'inherit';
      return this;
   },

   setBackground: function (background) {
      this.e.style.background = background;
      return this;
   },

   getValue: function () {
      // body...
      return this.e.value;
   },

   setValue: function (newval) {
      this.e.value = newval;
      return this;
   },

   toggle: function () {
      if (this.e.style.display !== 'none') {
         this.e.style.display = 'none';
      } else {
         this.e.style.display = '';
      }
      return this;
   },

   setSize: function (height, width) {
      this.e.style.height = height + 'px';
      this.e.style.width = width + 'px';
      return this;
   },

   setText: function (text) {
      // body...
      this.e.innerHTML = text;
      return this;
   },

   appendText: function (text) {
      // body...
      this.e.innerHTML += text;
      return this;
   },

   getText: function () {
      // body...
      return this.e.innerHTML;
   },

   setColor: function (color) {
      // body...
      this.e.style.color = color;
      return this;
   },

   getColor: function () {
      // body...
      return this.e.style.color;
   },

   getBackground: function () {
      // body...
      return this.e.style.background;
   },

   setFontSize: function (size) {
      // body...
      this.e.style.fontSize = size + 'px';
   },

   getFontSize: function () {
      // body...
      return this.e.style.fontSize;
   },

   setFontFamily: function (font) {
      // body...
      this.e.style.fontFamily = font;
   },

   getFontFamily: function () {
      // body...
      return this.e.style.fontFamily;
   }
};


Please help me find the problem(else I am going to be killed :O, and I am seriously, its stuck my class progress on very important prject).


Thanks alot,
Frost


Post a Reply

Replies

- page 2
Oldest  Newest  Rating
+1 William Frost · May 10, 2015
Still not working
+1 William Frost · April 11, 2015
UP?
0 Tatrasiel R · April 8, 2015
I am struggling to understand what you want exactly, but I think these can help

http://www.w3schools.com/jquery/html_append.asp


From looking around, it looks like you might need Jquery or JSON for this kind of thing. I am sure some one can provide a much better answer, as I am pushing for Javascript to cease to exist.

http://stackoverflow.com/questions/1385641/how-to-load-some-html-and-append-to-body-with-jquery
0 Tatrasiel R · April 8, 2015
Of course! Just not everyone understands that Jquery is an extension of Javascript. I just didn't want him to try something out, say it didn't work, when it just requires the imports.

Looking at it now, I did write that poorly.
0 Garrett Gillette · April 14, 2015
I am honestly confused at your problem your not really explaining what is wrong which is probably why it isn't solved yet post with some more detail and I will see if I can help.
0 Tatrasiel R · April 9, 2015
Samuel did resolve your issue , yes?
0 Tatrasiel R · April 10, 2015
Yeah, I am not sure.

I imagine that you shouldn't be appending to a div dynamically but rather to a variable. I am not sure though, I don't use Javascript anymore.
  • 1
  • 2

Javascript

107,090 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators