-1

I have javascript function to hide or show element but it's not working:

function detail(e) {
    var parent = e.parentNode;
    var next = parent.nextSibling;
    if (next.style.display == 'none') {
        row.style.display = '';
    } else {
        row.style.display = 'none';
    }
}

can anyone help me about this problem ?

thanks

thefourtheye
  • 233,700
  • 52
  • 457
  • 497

3 Answers3

1

parent.nextSibling selects a TEXT_NODE (nodeType = 3), not the next tr

Try this:

var next = parent.nextSibling;
while (next.nodeType != 1) {
   next = next.nextSibling;
}
Roland Jansen
  • 2,733
  • 1
  • 16
  • 21
0

If the element you are checking for 'display == none', then use:

function detail(e) {
    var parent = e.parentNode;
    var next = parent.nextSibling;
    if (next.style.display == 'none') {
        next.style.display = '';
    } else {
        next.style.display = 'none';
   }   
}

If not, then what is 'row'?

bcarn
  • 133
  • 6
0

A simple example to show/hide a div element.

function fun(){
    var ele = document.getElementById("testDiv");
    if(ele.className==="show"){
        ele.className="hide";
    }
    else{
        ele.className="show";
    }
}

http://jsfiddle.net/imrukhan/7j8ZS/1/

Better if you provide a complete html.