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 1
Oldest  Newest  Rating
+2 Samuel Oloruntoba · April 8, 2015
I change the function because i had underscore js on my page


function S(id) {
var about = {
      Version: 0.3,
      Author: "The Frostinator",
      Created: "July 2014",
      Updated: "March 2015"
   };

if (id) {
if (window === this) {
    return new S(id);
}

    this.e = document.getElementById(id);
      return this;
}
   
  return about;
};


S.prototype = {
   setText: function (text) {
      this.e.innerText = text;
      return this;
   },

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

   getText: function () {
      return this.e.innerText;
   }
};
+2 Ali Hassan · May 16, 2015
Well this is strange cuz when i copy and pasted your code it worked.......if you are writing this script in the head section try moving it to the end of the body , if not then something else is making a conflict with it..

But the code as it is has no problems at all tho......try using it in a brand new html that has nothing else than this script and only the div like i did and it will work..
+1 William Frost · April 11, 2015
Up??
+1 William Frost · April 12, 2015
Guys?
+1 William Frost · April 8, 2015
Its just not appending it to the div, and like "crashing" everything else. Have no idea why.
Thanks for who answered
+1 William Frost · April 9, 2015
Up?
+1 William Frost · April 9, 2015
Nope. same thing
+1 William Frost · April 14, 2015
The only problem is idk wat the problem, I call the func in the begining of the post and everything crushes after that :(
+1 William Frost · April 10, 2015
Up?
+1 William Frost · April 15, 2015
Please?
  • 1
  • 2

Javascript

107,103 followers
About

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

Links
Moderators