Few days ago, I was recalling my Java script skill. I was generating Grid using java script script. Instead of using Display property (‘none’ or ‘block’) to show or hide the control, I was creating and removing element each time. Creating element is not a big deal. However the script for removing element is different in IE and Firefox.
In IE, we can remove the element using, however this will not work in Firefox.
document.getElementById(“ControlID”).removeNode(true);
Fig -(1) Script to remove element in IE.
In Firefox, you have to use,
var Node1 = document.getElementById(“ParentControlID”);
Node1.removeChild(Node1.childNodes[0]);Fig -(2) Script to remove element in Firefox.
Below is the sample code for the same.
var Node1 = document.getElementById(“Parent”);
var len = Node1.childNodes.length;
for(var i = 0; i < len; i++)
{
if(Node1.childNodes[i].id == “Child”)
{
Node1.removeChild(Node1.childNodes[i]);
}
}
Fig -(3) Script to remove child element in Firefox.
can you show screenshots of what you mean in remove/delete element? which element are you referring to?
problem with loop to go thru children. As you delete them, the array of childnodes get shorter and the code loop overruns the array and you get an error.
Better is to delete from beginning, as in line:
Node1.removeChild(Node1.childNodes[0]);
There is an even better way.
If you have:
- ParentControlID
—- ControlID
Create an invisible or zero-height element (let’s say “RemoveID”)
then do this:
- ParentControlID
—- ControlID
- RemoveID
// MOVE ControlID to the RemoveID container
document.getElementById(‘RemoveID’).appendChild(document.getElementById(‘ControlID’));
// Empty the contents of RemoveID
document.getElementById(‘RemoveID’).innerHTML = ”;
hi, i was seeking for something related and i went here. i would be so thanks if u can helpe me. im trying to enable/disable a group of radiobuttons by one radio button.
but it only works in ff, no in ie…
thats the function:
function radioEntrada(obj) { //Entrada
if (document.stat.tipo[0].checked)
//if (document.getElementsByName(“tipo”)["0"].checked==true)
{
var radios = document.forms['stat'].elements['cdMunicipio'];
for(var i = 0, t = radios.length; i < t; radios[i++].disabled = (!obj.true));
document.getElementById(‘contrato’).style.visibility = ‘hidden’;
var radios2 = document.forms['stat'].elements['forma'];
for(var i = 0, t = radios2.length; i < t; radios2[i++].disabled = (!obj.true));
}
}
hope u can help me, cuz i dont what to do…
greetings from brazil.
var r1 = document.getElementById(“controlID”);
r1.removeAttribute(’style’);
r1.removeAttribute(‘innerHTML’);
r1.removeAttribute(‘onmousedown’);
r1.removeChild(r1.childNodes[0]);
r1.removeAttribute(‘id’);
Dear Chirag,
I got a problem while removing elements from node (specially in FF). I have found that below code is working fine instead of for loop.
while (Node1.hasChildNodes())
Node1.removeChild(Node1.childNodes.item(0));
hi chirag,
company paisa aape che to koi var code bode to kar…:-)
Vijay sir,
Sorry I will take from next time
Hi Ricardo,
Try to put this javascript function in your code and call it from the click of radiobutton:
function DisableRadioButton() {
getObj(findControlClientID(‘MyRadioButton1′,’RadioButton’)).disabled = true;
}
I checked, this will work in both FF and IE.
Get back if you still face any issue.
Thanks!!
Hardeep,
Thanks, Highly appreciated.
Hi,
I use allways the method
object.parentNode.removeChild(object);
It works in IE & FF.
please remove
nice thanx
hi gyuis, what’s on your fingers? on the top photo
Thank you very much…. Helped me to resolve a crtical bug…
I found this site very useful.
Your javascript “skill” as you put it doesn’t work.