Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript HTML jQuery
Hello Friends,
 
I am working with HTML,javascript and jquery in my code, dynamically add and delete the new elements to the existing "div".
 
Adding new element is working fine, but when I click on delete to remove the element, I get the Main Container object and also the child element object within the button exists and was clicked.
 
now the problem comes when I try to delete the element, I am getting the object till the html table control that contains the controls, but do not get the div that is containing the table.
 
Note : the div contains the table is the child div/element.
 
To Add element.
var ab = '<table rules="none" width="100%">
<tr>
<td class="optHdBg">
<a><img src="themes/theme_blog/images/icons/delete.png" name="delete"  önclick="javascript:remove_block(this);"/></a>
</td></tr></table>';
 
function add()
{
var lstChild = $("#contControls").children().last();
var containerElement = document.getElementById("contControls");	
var newElement = document.createElement("div");
$(newElement).addClass("optionPane");
document.getElementById("contControls").appendChild(newElement);
}
 
function remove_block(obj)
{
  var mainContainer = $(obj).parents("div #contControls");
  var mySelf = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
  mainContainer.removeChild(mySelf);
}
 
problem occurs with mySelf control that is not accessing the div control that contains the table, due to that delete operation doesn't work.
 

please guide me.
Thanks.
Posted 4-Sep-12 0:41am
Comments
Zoltán Zörgő at 4-Sep-12 5:50am
   
You are mixing JQuery with plain Javascript. JQuery has all that you need. Consult it's documentation first.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

See this for append and add functionality in JQuery: http://www.mkyong.com/jquery/jquery-append-and-appendto-example/[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 150
2 PIEBALDconsult 110
3 Richard MacCutchan 105
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 4 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100