39

I want to select an anchor inside a div like this

<div class="response content">
  Disapproved Bank Mandiri<br><br>
  <p>
    <a class="showlist" href="#">Back to list?</a>
  </p>
</div>

What is the jquery to do this ?

strike_noir
  • 4,000
  • 11
  • 53
  • 97
  • 8
    you should have read selectors ( http://api.jquery.com/category/selectors/ ) in jQuery before asking. – Reigel Apr 20 '10 at 04:42

4 Answers4

62

Any anchor in a div with "response" and "content" classes:

$('.response.content a')

Or only anchors with a class of "showlist":

$('.response.content a.showlist')
awgy
  • 15,996
  • 4
  • 23
  • 17
11

If you require both classes on the DIV:

$("div.response.content a.showlist");

If not,

$("div.response a.showlist");

To learn more about basic usage of jQuery Selectors, visit http://api.jquery.com/category/selectors/

Sampson
  • 259,174
  • 73
  • 529
  • 557
4

Another way you could solve this is using jQuery .find()

Here is an example of using find() to select all elements in a div with the class "response content".

jQuery('.response.content').find('a');

This is also a helpful post that visits the topic of selectors vs. .find()

Community
  • 1
  • 1
ScottyG
  • 2,948
  • 1
  • 29
  • 42
0

You can use :

$('.response').find('a');

Or

$('.response').find('.showlist');
Hygison Brandao
  • 432
  • 3
  • 12