Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2005
    Location
    Homs, Syria
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DOM: referencing rows for removal.

    Hello.

    I've had to come up with a side-script to delete a row based on its contents no matter which row it is.

    Now my whole program needs to be changed and I want to know if there is any way to reference a row for deletion, like using the this operator, for instance.

    i.e.: I want to hit an image inside a row and the result should be the removal of that very row with all its contents.

    PS: this doesn't seem to work with row removal commands. It says the object does not support the current method.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Play with parentNodes:
    Ex:
    PHP Code:
    <script type="text/javascript">
    function 
    removeThisRow(obj){
    var 
    myRow=obj.parentNode.parentNode;
    myRow.parentNode.removeChild(myRow)
    }
    </script>


    ... no matter what
    <tr>
    ... no matter what
    <td>
    ... no matter what but not a parentNode for img
    <img src="removal.gif" onclick = removeThisRow(this)>
    ... no matter what
    </td>
    ... no matter what
    </tr>
    ... no matter what 
    Last edited by Kor; 11-28-2005 at 11:02 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    With a small modification, that could allow for any number of intermediate parent elements:
    Code:
    function removeThisRow(obj)
    {
    	var myRow = obj.parentNode;
    	while(myRow.parentNode.nodeName.toLowerCase() != 'tr')
    	{
    		myRow = myRow.parentNode;
    	}
    	myRow.parentNode.removeChild(myRow);
    }
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Yes, brothercake, sorry, suprisingly I had forgotten about that, even I usually use the code exactly in that manner... Must be the entire day tiresome's fault...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New to the CF scene
    Join Date
    Nov 2005
    Location
    Homs, Syria
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you all. Surprisingly, I haven't even thought of using removeChild with parentNode . Now I feel stupid. :B

    Things are working fine now, thanks again. =D

    The problem I talked about before was that I was using the deleteRow[0] handler which requires the row index. The problem appears when having to delete more than one row, because while the command could work the first time, all the indexes change, and if the removal function itself doesn't change, then it's rendered useless.

    I could work that problem out by playing with indexes as variables, but it becomes next to impossible when having to deal with 13200+ item. ^^;

    Anyway, this and parentNode, thank you.
    Special thanks for brothercake for the little trick.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •