0

I have to select an <a> element from the given class of objects. when i click on the anchor tag in the showcase_URL class, i want the jquery function to get the value from <a> tag. How can this be done?

I cannot make this an id as I am running a while loop to construct all the elements in php. there would be multiple objects of this class. there is no definite selector through which I can get the value of the anchor tag. Help would be much appreciated.

        echo '<div id="content">';  
        echo '<div class="showcase_data">';
        echo    '<div class="showcase_HEAD">'.$row->title.'</div>';
        echo    '<div class="showcase_TYPE">'.$row->type.'</div>';
        echo    '<div class="showcase_date">&nbsp;&nbsp;'.$row->date.'</div>';
        echo    '<div class="showcase_THUMB" style="float: left;" ></div>';
        echo    '<div class="showcase_TEXT">'.$row->details.'</div><br/>';
        echo    '<div class="showcase_URL"><a class="purl" value='.$row->num.'href="'.$row->url.'">PROJECT URL</a></div>';
        echo    '</div>';
        echo    '</div>';

5 Answers 5

2
$('.showcase_URL a').click(function(e) {
  alert($(this).attr('value'));
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the attr() function like this:

$(".showcase_URL a").click(function() {
  alert($(this).attr("value"));
});

Note: You should have quotes and a space here like this:

value='.$row->num.'href="'.$row->url.'"

to:

value="'.$row->num.'" href="'.$row->url.'"

Comments

1
$('a').click(function(){
   var value = $(this).attr("value");
});

This will monitor the value element on all anchor tags clicked. You can filter that by class, or only those anchor tags beneath the showcase_URL div. Your question really doesn't specify what exactly you need.

Comments

0
$('.showcase_URL a.purl').click(function(){
   alert($(this).attr('value'));
})

Comments

0

To get text or any other data bind on click event to your anchor:

$('a.purl').click(function(){
    var text = $(this).html();
});

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.