Welcome Guest [Log In] [Register]
Important Links
Contests & Events
Latest Announcements
Forum Guidelines
Meet the Staff
Update Log
  • SOTM #3 [Winner]
  • TOTM #3 [Winner]
  • October Updates!
  • Become a Contributor!
  • Affiliate with us!
    Add Reply
    [C] Weird validation error in JavaScript library
    Topic Started: Sep 11 2015, 01:56 AM (268 Views)
    Flash
    Member Avatar


    So, I've been playing around with JavaScript a bit, recently, and started creating a small library. Here's my code...

    Code:
     

    var $ = function (selector) {
    if (selector) {
    if (window === this) {
    return new $(selector);
    }
    }
    this.selector = document.querySelector(selector);
    return this;
    };

    $.method = $.prototype = {
    hide: function () {
    this.selector.style.display = 'none';
    return this;
    },
    show: function () {
    this.selector.style.display = '';
    return this;
    },
    html: function (html) {
    this.selector.innerHTML = html;
    return this;
    },
    css: function (property) {
    var style;
    style = window.getComputedStyle(this.selector);
    style.getPropertyValue(property);
    return this;
    },
    col: function (color) {
    this.selector.style.color = color;
    return this;
    },
    bg: function (bg) {
    this.selector.style.background = bg;
    return this;
    },
    margin: function (margin) {
    this.selector.style.margin = margin;
    return this;
    },
    padding: function (padding) {
    this.selector.style.padding = padding;
    return this;
    },
    attr: function (attr) {
    this.selector.getAttribute(attr);
    return this;
    },
    class: function (type, className) {
    if (type === 'add') {
    this.selector.classList.add(className);
    return this;
    }
    else if (type === 'remove') {
    this.selector.classList.remove(className);
    return this;
    }
    else {
    return false;
    }
    },
    val: function () {
    return this.selector.value;
    }
    };


    It works perfectly fine, but jsFiddle shows a validation error on line 35. ('this.selector.style.background = bg;') It's identical to my other methods, and they validate okay, so I don't quite get what's wrong with this one.

    Help?

    Edit: Fixed itself after I added a .toggle() method. Weird.
    Edited by Flash, Sep 11 2015, 06:33 AM.
    Posted Image
    Off
    Profile
    Quote
    Top
     
    -The-
    Member Avatar
    #the { display: all; }

    So this can be closed then? Or are you still looking for an explanation why it now works?
    -The- | Foundation Manager
    Skype: JamesAdams1001 | PM me | Ask Me Anything
    Suggest Anything. Ask Anything. Foundation.
    Posted Image Posted Image Posted Image Posted Image
    Off
    Profile
    Quote
    Top
     
    Flash
    Member Avatar


    -The-
    Sep 12 2015, 08:26 AM
    So this can be closed then? Or are you still looking for an explanation why it now works?
    Oh, yeah, you can close it.
    Posted Image
    Off
    Profile
    Quote
    Top
     
    -The-
    Member Avatar
    #the { display: all; }


    Support Issue Resolved!

    This support request has been resolved and has been marked as complete. This is only to help sort the forum, the topic will remain open in case you experience more issues with this topic.

    If you have another support request with another issue, please post a new topic.


    -The- l Foundation Staff
    -The- | Foundation Manager
    Skype: JamesAdams1001 | PM me | Ask Me Anything
    Suggest Anything. Ask Anything. Foundation.
    Posted Image Posted Image Posted Image Posted Image
    Off
    Profile
    Quote
    Top
     
    1 user reading this topic (1 Guest and 0 Anonymous)
    « Previous Topic · Support Zone · Next Topic »
    Add Reply


    Foundation Affiliates (Click Here)

    Discuss Academy Foundation