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
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
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.
Like this:
$('a').each(function()
{
alert(this.id + ': ' + $(this).text());
});
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(); });