javascript - How do you move sibling elements order up/down in prototype 1.5.1? -


I try to set up a function to allow 'up' and 'down' of the table row in a form I am doing The number of table rows is dynamic - the user can press a button to add extra rows. Each table row has several fields, with a different class names, there is a headline and footer row, so check the box of Hexa ClassName.

For the first time I wrote this function successfully to use with prototype 1.6 before I version 1.5.1. Upon the time available for testing we will upgrade to the latest version of the prototype, but I need to work under the current version of my project. The main problem is that in 1.5 you can not just insert an element as the content of an entry, that means that I need the HTML of the element that I want to insert. It raises the issue that when I reach HTML for Element (Variable "Insert HTML") then this is the original HTML and does not include the information entered by the user in the respective form elements.

Any help would be greatly appreciated.

  moveDataDef: function (num, dir) {var targRow = $ ('dataDefItem' + num); Var content = targRow.inner HTML; Var brother siblings; Var insertHTML = targRow.inspect () + targRow.innerHTML + '& lt; / Tr & gt; '; If (DIR == 'up') Brother Sister = Targarov Previous siblings (); Other siblings = Targrave No. If (Sister [0] .hasClassName ('dataDefItem')) {targRow.remove (); If (DIR == 'up') new insertion Before this (brother siblings [brother sisters lanti-1]. Id, Targarov); Second new insertion After (siblings [0] .id, targRow); }}  

I think, you can change this code to replace your lower position If the block uses the native DOM function, that is, insert () :

  if (siblings [0] .hasClassName ('dataDefItem ')) {Var targetParent = targRow.parentNode; Var brother = siblings [0]; If (dir == 'up') {targRow.remove (); TargetParent.insertBefore (targRow, bro); } Other {sibling.remove (); TargetParent.insertBefore (brother, targRow); }}  

For your reference, if you are interested, then this is my POC code:

  & lt; Table id = "tb1" & gt; & Lt; Tbody & gt; & Lt; Tr id = "tr1" & gt; & Lt; TD & gt; 1 & lt; / Td> & Lt; / Tr & gt; & Lt; Tr id = "tr2" & gt; & Lt; TD & gt; 2 & lt; / Td> & Lt; / Tr & gt; & Lt; Tr id = "tr3" & gt; & Lt; TD & gt; 3 & lt; / Td> & Lt; / Tr & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; Script type = "text / javascript" & gt; / * & Lt ;! [CDATA [* / (function () {var trr3 = $ ('tr3'); var tp = trr3.parentNode; var trr1 = trr3.previousSiblings (); trr3.remove (); tp.insertBefore (Trr3, trr1 [ 0]);}) (); / *]] & Gt; * / & Lt; / Script & gt;  

Thanks.

Update: Fix Typo ('' 'and'} ').


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -