0

Here I have four tds which are clickable and I have four more tds which have ids and concerned data within them. I want to display data when concerned clickable tds are clicked. This I want to do using JavaScript.

Here is my JavaScript code:

var _hidediv = null;
function showdiv(id) {
    var div = document.getElementById(id);
    div.style.display = 'block';
    if(_hidediv)
        _hidediv();
    _hidediv = function () {
         div.style.display = 'none';
    };
1
  • If I remove window.addEvent method then it works fine for me. Infact I create a test project and it works fine if I don't include this method wrapper Commented Dec 26, 2012 at 7:15

3 Answers 3

1

Is this that you need?

http://jsfiddle.net/f8VL8/11/

var showed = 'news1';

function showdiv(id) {
    if(showed && showed !== id) {
        document.getElementById(showed).style.display = 'none';
    } 
    document.getElementById(id).style.display = 'block';
    showed = id;
}
​
Sign up to request clarification or add additional context in comments.

1 Comment

remember last showed; when click, hide previous and show what you need. And in jsfiddle, make your js functions out of onload or ready wrap if you want to call it outside
0

rewrite in jquery version

http://jsfiddle.net/f8VL8/13/

js

$('.content').click(function(){
    var target = $(this).attr('href');
    //console.log(target);
    if(target){
        $('.result td').hide();
        $(target).show();
    }
});

HTML

<tr >
      <td><a href="#news1" class="content" >iCMS</a></td>
 </tr>
 <tr>
       <td><a href="#news2" class="content" >SMSC</a></td>
 </tr>
 <tr>
       <td><a href="#news3" class="content">SMS Gateway</a></td>
 </tr>
 <tr>
      <td><a href="#news4" class="content">WAP Gateway</a></td>
 </tr>

Comments

0

On left side in JSfiddle, change onLoad to no wrap (head) and your script will work.

http://jsfiddle.net/f8VL8/14/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.