[jQuery] Newbie question on selectors

2009-06-03 Thread Dave Maharaj :: WidePixels.com
I have a page with 6 links that each have a unique class ;
edit_profile
edit_preferences
edit_journal
edit_entry and so on
 
now I built 1 function based off edit_profile 
$(a.edit_profile).click(function(){
var url_id = $(this).attr('href');
do stuff..
});
 
but rather than writing the same function and changing the selector
everytime how can i get this all into 1 function? 
 
Thanks,
 
Dave 


[jQuery] Newbie question- declarative selectors inside procedural code

2009-05-25 Thread colin_e

Hi. I'm very new to jquery, and a lightweight coder, so apologies for
the newbie question.

I think I understand the implied loop declarative nature of jquery
selectors, that say (sort-of) for everything matching the selector
do{ some stuff }

What i'm struggling to get my head around is how this works inside a
function once you HAVE a this object?

Example:
I have a list of the form-

ul id=map
  lia class='EM' href='#' title='East Midlands'spanEast
Midlands/span/a/li
  lia class='NE' href=# title='North East'spanNorth East/
span/a/li
/ul

This inside my document.ready I have a function like this-

$('#map li').hover(
function(){
region= $('this a:first').attr('class');  // Tries to 
find the
class of the first a in li
  //
but always returns undefined??
do_something_with_the_region();
},
function(){
undo_something_with_the_region();
}
);


The piece that says region= $('this a:first').attr('class'); is my
(clearly incorrect) attempt at the incantation to say  Give the
current object (an il), return the class attribute of the first
anchor that is a child of the current item.

I suspect I haven't got the right idea at all, can anyone point me in
the right direction?

Regards: colin_e