jquery - Paragraph numbers changing HTML JAVASCRIPT -
i'm working list elements can added js following code:
function getmovementbuttons(size, articleid, articletitle, articletype){ var lowerarticletype = articletype.tolowercase(); var html = '<div>'+ '<span style="vertical-align: top">'+ size + '<span style="vertical-align: top">.</span> '+ '</span>'+ '<span style="vertical-align: top" class="'+lowerarticletype+'-title displaying-'+lowerarticletype+'-id' + articleid +'">' + articletitle + '</span>' + '<input class="'+lowerarticletype+'-button-delete" type="button" value="' + '<%= languageutil.get(pagecontext, "global.action.delete")%>' + '" onclick="removearticle(this,\''+articletype+'\')"/>' + '<div class="'+lowerarticletype+'-div-move"><input class="'+lowerarticletype+'-button-up" type="button" value="" onclick="movearticleup(this,\''+articletype+'\')"/>' + '<input class="'+lowerarticletype+'-button-down" type="button" value="" onclick="movearticledown(this,\''+articletype+'\')"/>' + '</div>'+ '</div>'; return html;
i have function removearticleline.
function removearticleline(button) { var parentdiv = button.parentnode var articlelistdiv = parentdiv.parentnode; articlelistdiv.removechild(parentdiv); }
there problem, because if delete object paragraphs don't change numbers. ask give me hint how can change these numbers js. i'm adding working functions can us. it's moving properly:
function movearticleup(button, articletype) { var articlediv = button.parentnode.parentnode; var parentdiv = articlediv.parentnode; var prevarticlediv = articlediv.previouselementsibling; if (prevarticlediv && prevarticlediv.tagname == 'div') { var articleidvalue = getarticleidvalue(articletype); var ids = articleidvalue.split(','); var articleid = getarticleidfromarticlediv(articlediv, articletype); var articleidindex = ids.indexof(articleid); swapposition(ids, articleidindex, articleidindex - 1); setarticleidvalue(articletype, ids.join()); removedarticlediv = parentdiv.removechild(articlediv); parentdiv.insertbefore(removedarticlediv, prevarticlediv); console.log(articleidindex); prevarticlediv.firstelementchild.innerhtml = articleidindex + 1 + '<span style="vertical-align: top">.</span> '; articlediv.firstelementchild.innerhtml = articleidindex + '<span style="vertical-align: top">.</span> '; } } function movearticledown(button, articletype) { var articlediv = button.parentnode.parentnode; var parentdiv = articlediv.parentnode; var nextarticlediv = articlediv.nextelementsibling; if (nextarticlediv) { var articleidvalue = getarticleidvalue(articletype); console.log(articleidvalue); var ids = articleidvalue.split(','); var articleid = getarticleidfromarticlediv(articlediv, articletype); console.log(articleid); var articleidindex = ids.indexof(articleid); console.log(articleidindex); swapposition(ids, articleidindex, articleidindex + 1); setarticleidvalue(articletype, ids.join()); console.log(ids.join()); removedarticlediv = parentdiv.removechild(nextarticlediv); parentdiv.insertbefore(removedarticlediv, articlediv); console.log(nextarticlediv.firstelementchild.innerhtml); console.log(articlediv.firstelementchild.innerhtml); nextarticlediv.firstelementchild.innerhtml = articleidindex + 1 + '<span style="vertical-align: top">.</span> '; articlediv.firstelementchild.innerhtml = articleidindex + 2 + '<span style="vertical-align: top">.</span> '; } }
let me add 2 screenshots of displayed table:
after remove line should loop array of elements , assign new numbers them. code not tested, should works
function removearticleline(button) { var parentdiv = button.parentnode; // getting number of deleting div var divnumber = parseint(parentdiv.firstchild.textcontent); var articlelistdiv = parentdiv.parentnode; articlelistdiv.removechild(parentdiv); // need loop elements after deleted div, because elements before did not change theit number (var = 0 || divnumber; < articlelistdiv.children.length; i++) { //changing number articlelistdiv.children[i].firstelementchild.innerhtml = (i + 1) + '<span style="vertical-align: top">.</span> '; } }
Comments
Post a Comment