Skip to content Skip to sidebar Skip to footer

Javascript What Wrong In My Function?

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.d

Solution 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;
}

Solution 2:

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'?


Solution 3:

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.


Post a Comment for "Javascript What Wrong In My Function?"