jaiiiii
jaiiiii

Reputation: 3

Using jQuery to Retrieve Text from an HTML Element

So i have a set of links that all must call the same ajax function through jQuery. To simplify this, I have used

$('#nav').click(function() {...});

where each has the same <a id="nav"...>I want to retrieve only the text of the HTML element clicked on, but using the .text() function in ajax retrieves the text of each $('#nav') element. Any suggestions?

Upvotes: 0

Views: 86

Answers (1)

Tomm
Tomm

Reputation: 2142

CSS id's are only to be used once. Change your #nav to a class and you're good:

<a class="nav">

and get the text like this

$('.nav').click(function() { alert($(this).text()); });

Upvotes: 5

Related Questions