trying to understand js/jquery syntax [solved]
The
jquery crash course is great and I have found the
How to Get Anything You Want tutorial vital in getting as far as I have with this problem. I've been at it for half a day but I just haven't got a grasp of js syntax yet (am loving that jquery is close to css which is why I have gotten this far!)
Rather than spend ages outlining the issue and dumping a whole lot of code and urls here I will ask just small syntax questions at a time - that way, those of you blessed with the ability to comprehend js can give quick answers rather than having to learn the whole issue.
question 1: I have a variable set (called thisTarget) I want to select a div that has an id of that variable so I can show it. The following code is what I am trying to do but I have no idea how to write it so that thisTarget is the value of the id attribute
$(div#(thisTarget)).show('fast');
question 2: I want to apply the attibute id with a value of "active" to an li within the div#navigation - however, the attribute needs to be applied to the li that parents the 'a' tag that was clicked
My attempt below
$('#navigation (this).parent').attr(id, active);
Now, for context, I have included the whole function but hopefully you won't need to look at this. The commented lines are ones I haven't got to work and the uncommented lines work:
-
$(document).ready(function(){
$(".navbar a").click(function(){
// Assign value of the chosen link in navbar 'a' tag as a variable using the value of the title attribute
// I tried to use the rel attribute for this but it wouldn't work!!!?
var thisTarget = $(this).attr('title');
$("#navigation").show("fast");
$(".popup").hide("fast"); // to close the side panels (poll/nextweek/btndaily) on the home page
// Remove id="active" attribute and add it to the li that holds the clicked a tag
$('.navbar li#active').removeAttr('id');
//$('#navigation (this).parent').attr(id, active);
// Show chosen subnav (using thisTarget variable set previously) - and hide all other subnav's
//$(div#(thisTarget)).show('fast');
//$('.subnav').hide("fast");
return false;
});
$("a#close").click(function(){
$("#navigation").hide("fast");
return false;
});
});