Reputation: 63
I am having issues showing one div then hiding the previous div.
var newElem = '#ID' + numVariable;
$('.elemPropGlobal').hide();
$(newElem).click(function (){
$('.elemPropGlobal').hide();
$($(this).attr('id') + 'Properties').show();
}
Divs that I click on
<div class="something" id="ID1" > some data</div>
<div class="something" id="ID2" > some data</div>
Divs that should show and hide
<div class="elemPropGlobal" id="ID1Properties" >
<div class="elemPropGlobal" id="ID2Properties" >
Upvotes: 0
Views: 161
Reputation: 13736
I don't know if it is an oversimplification, but you're not setting the click event for both divs and you're forgetting the hash in the second selector:
$(newElem).click(function (){}); //newElem is #ID1 or #ID2
you could do
$(".something").click(function (){
$('.elemPropGlobal').hide();
$("#" + $(this).attr('id') + 'Properties').show(); //Remember the hash!
});
Upvotes: 0
Reputation: 65166
Currently you're looking for elements that are named ID1Properties
etc. You need a #
prefix to search by id!
$("#" + $(this).attr('id') + 'Properties').show();
Upvotes: 0