I have a `javascript` that when press `Ctrl` + `Enter` it will call `CtrlEntInsertData()`:

```
function KeyPress(e) {
      var evtobj = window.event? event : e
      if (evtobj.keyCode == 13 && evtobj.ctrlKey) {
        CtrlEntInsertData();
      }
}

document.onkeydown = KeyPress;

function CtrlEntInsertData() {
var target = document.querySelector("input");
var tarpos = getPosition(target);    //!!<-- This work!
target.setAttribute('data', 10);     // Error line
console.log(tarpos.x+" "+tarpos.y);  //!!<-- This return x, y of target
   console.log(target);              //!!<-- NULL
}

function getPosition(element) {
    var xPosition = 0;
    var yPosition = 0;

    while(element) {
        xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
        yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
        element = element.offsetParent;
    }
    return { x: xPosition, y: yPosition };
  }

```

Here is my `HTML`:

```
<div class="input" data="0" ></div>

```

I got an error:

> 
> TypeError: null is not an object (evaluating 'target.setAttribute')
> 
> 
> 

But when I use it to `getPosition()`, it did return me something. Why is this and how to get it to work?