开发者

how to get the value from a CSS class object in javascript

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>';


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


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.'"


$('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.


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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜