0

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?

1 Answer 1

5

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()); });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.