tags:

views:

2400

answers:

2

Hello guys, I want to get the id of the clicked element and then show divs that match this id. I am using the following code, and it's not working. Please help.

$(function () {  

var tabContainers = $('div.difContetform > div');
    $('div#head-nav ul a').click(function (event) { 
        $('div#head-nav ul a').removeClass('current');
        $(this).addClass('current');
        var current_id = $(this).attr("id");
        var targeted='DIV'+current_id;
        $(targeted).show();
        $(targeted:not).hide(); 
        // 
        return false; 
     })
});
+5  A: 

You want to use the right selector syntax to grab your divs by id, which is the string #id... Therefore:

 $('#'+targeted).show();
 $('something:not(#'+targeted+')').hide();

EDIT: Looking at this again (double-take), you can't just hide everything that doesn't match, as it will hide your whole page. You'll need to make sure you're selecting only DIVs, but not the one you want to show. How that works depends on your page layout (hence the something in the example above).

Adam Bellaire
A: 

Thanks a lot dear now i am able to show the div but could't hide others. as you said all page disappear i have on container id=formContainer and other divs (child of that id div) under this id show hide and 1 shown that is clicked.

i am using below syntax

$('div#difContetform > div:not(#'+targeted+')').hide();

but its not working although page not disappear but not hiding other divs

Yasir
Hmm, I don't know the layout of your page so I can't tell what is wrong with that selector. It says: Find a div with id 'difContetform', then find all of its immediate children which are divs, excluding those which have the targeted id, and hide them.
Adam Bellaire
Do you have any of your class or ID names misspelled? Such errors are silent.
Adam Bellaire
no misspelled my structure is 3 divs in one parent div i only want to hide show functionality in this parent div.
Yasir
:) sorry Adam again thanks a lot for help this was misspelled problem i was using class instead of id.
Yasir