Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating Div tags with JSON

    I have a Dom/json code that creates 2 divs and adds name inside those divs.
    However with the below code, its jus creating 2 empty divs. Can somebody help ??

    --- CODE

    var Card = (function () {
    var Card={
    template: "<div class='Card'><span class='name'></span></div>",
    init : function (params) {
    this._parseTemplate();
    this.setName(params.name);
    },

    setName: function (name) {
    this.name = name;
    if (typeof name === 'string') {
    var nameNode = this.domNode.getElementsByClassName('name')[0];
    nameNode.innerHTML = this.name;
    }
    },

    _parseTemplate: function () {
    var temp = document.createElement('div');
    temp.innerHTML = this.template;
    this.domNode = temp.firstChild;
    }
    };
    return function () {
    Card.init(arguments);
    return Card;
    };
    }());

    var card1 = new Card({
    name: 'Joe Shmoe'
    });
    var card2 = new Card({
    name: 'Jane Doe'
    });

    console.log(card1.domNode, card2.domNode);

  • #2
    Regular Coder
    Join Date
    Jan 2013
    Location
    Sunnyvale, CA
    Posts
    144
    Thanks
    11
    Thanked 7 Times in 7 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •