brainbug
brainbug

Reputation: 65

jquery loop links

i have a php-loop that generates different results from the database, so my output might look like this:

<a href="blablabla">blabla</a> <a href="blablabla">blabla</a> <a href="blablabla">blabla</a> <a href="blablabla">blabla</a> <a href="blablabla">blabla</a> <a href="blablabla">blabla</a>

Now, I know how to get a clicked element by #id or .class but I don't know (and havent found) how to get a clicked link. (I wont to show the content of it's link in an other div. Do you have a solution?

Upvotes: 0

Views: 160

Answers (4)

daryl
daryl

Reputation: 15207

Not sure I fully understood your question, but is this what you were after?

$(function() {
    $('.yourlink').click(function(e) {
        e.preventDefault();
        $('#someDiv').load(this.href);
    });
});

Or maybe it was this:

$(function() {
    $('.yourlink').click(function(e) {
        e.preventDefault();
        $('#someDiv').html($(this).html());
    });
});

Upvotes: 0

Monday
Monday

Reputation: 1413

try this~

 $(function(){
    $('a').each(function(index) {
    alert(index + ': ' + $(this).text());
 });

Upvotes: 0

Kanishka Panamaldeniya
Kanishka Panamaldeniya

Reputation: 17586

$('a').live('click',function(e){

     e.preventDefault();
     var link = $(this).attr('href');

     $('.somediv').html(link);

});

Upvotes: 0

ShankarSangoli
ShankarSangoli

Reputation: 69915

$("a").click(function(e){
  e.preventDefault();
  $("targetDivSelector").load(this.href);
});

Upvotes: 2

Related Questions