jQuery function which creates div, rewritten in JavaScript not working -


i have function written in jquery , creates div selected element.

var createplaceholder = function createplaceholder(height) {     return $('<div></div>').css({         height: height + 'px',         margintop: (currentindex > 0 ? -margintop : -1) + 'px'     })     .addclass('placeholder'); }; 

and called this:

placeholderheight = dragging.outerheight() + margintop; placeholder = createplaceholder(placeholderheight); placeholder.insertafter(dragging); 

now pure js stuff! i'm trying same thing without jquery, i'm getting undefined errors , parent problems. did far:

var createplaceholder = function createplaceholder(height) {   var div = document.createelement('div');       div.style.height = height + 'px';       div.style.margintop = (currentindex > 0 ? -margintop : -1) + 'px';       div.setattribute('class', 'placeholder');        document.body.appendchild(div);    };  placeholderheight = dragging.outerheight() + margintop; placeholder = createplaceholder(placeholderheight); placeholder.parentnode.insertbefore(placeholder,dragging.nextsibling); 

tried way:

 placeholderheight = dragging.outerheight() + margintop;  var div = document.createelement('div');      div.style.height = placeholderheight + 'px';      div.style.margintop = (currentindex > 0 ? -margintop : -1) + 'px';      div.setattribute('class', 'placeholder');    div.parentnode.insertbefore(div, dragging[0].nextsibling); 

i error: typeerror: cannot read property 'insertbefore' of null

what i'm doing wrong? :/

well, modified code working condition can tested on page itself, because didn't supply playground link or rest of code...so here is:

var dragging = document.getelementbyid('question-header');   var createplaceholder = function createplaceholder(height) {   var div = document.createelement('div');   div.style.csstext = 'height:' + height + 'px; margin-top:' + (currentindex > 0 ? -margintop : -1) + 'px';   div.classname = 'placeholder';    return div; };  placeholderheight = dragging.clientheight + 10; placeholder = createplaceholder(placeholderheight); dragging.parentnode.insertbefore(placeholder,dragging.nextsibling); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -