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;
})
});
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With