Home › Forums › JavaScript › using ‘id’ to reference an object › Re: using ‘id’ to reference an object
OK, this was fun… I have finally solved my problem
to reference the id of an element, use .attr(‘id’)
here is the code that allows the accordion to ‘remember’ which section to show on page refresh/change
var iShow = 0;
var j = $(‘#accordion dd’).length -1;
var i = 0;
iShow = parseInt($.session(“eq”))-1;
$(‘#accordion dd’).hide();
$(‘#accordion dd’).eq(iShow).show();
$(‘#accordion dt a’).click(function(){
for (i=0; i<=j; i++) { if ($('#accordion dt a').eq(i).attr('id') == this.id) { //For some reason, the session object doesn't like 0, so I add 1 to the results here // and take it away when I am storing it in my iShow variable. $.session("eq",i+1); } } $('#accordion dd').slideUp(); $(this).parent().next().slideDown(); return false; }); });
have fun!