tags:

views:

28

answers:

3

hey all,

i have 2 simple links on my page. how do i use jQuery to get the id's or values of those links?

thanks, rodchar

+1  A: 

You can use:

$("your-selector-here").attr("id");

to get the ID, and:

$("your-selector-here").text();

to get the text enclosed in the link.

You'll need to decide how best to identify each link using a jQuery selector, and replace "your-selector-here" with your selector in the above examples.

richsage
+1  A: 

Like this:

$('a').each(function()
{
    alert(this.id + ': ' + $(this).text());
});
Greg
A: 

If your links are simple anchors you could do it this way:

To get the ID:

$("a").each(function() { $(this).attr("id"); });

To get the value or the text:

$("a").each(function() { $(this).text(); });
Joseph