Demo entry 6346646

456123

   

Submitted by anonymous on Feb 10, 2017 at 12:18
Language: JavaScript. Code size: 962 Bytes.

var addChild = function (th, id) {
  // добавить ребенка
  if (data[id]["childrenAge"].length < 3) {
    data[id]["childrenAge"].push(th.getAttribute("attr"));
  }
  // отрисовываем детей
  var tmpl = _.template( $("#template-childer").html() );
  var result = '';
  var age = null;
  data[id]["childrenAge"].forEach(function (elem, i) {
    if (elem == 2) {
      console.log(2);
      console.log(th.innerHTML);
      age = th.innerHTML;
    }else if (elem == 10) {
      console.log(10);
      console.log(th.innerHTML);
      age = th.innerHTML;
    }else {
      age = elem;
    }
    var res = {'id': id, 'age': age, 'id_age': i}
    result += tmpl(res)
  });
  th.parentElement.parentElement.parentElement.children[0].innerHTML = result;
  // скрываем выбор возраста
  th.parentElement.parentElement.children[0].classList.toggle('select-child');
  th.parentElement.parentElement.children[1].classList.toggle('display-block');
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).