0

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?

1
  • 1
    what exactly do you want to achieve? can you give a example? Commented Jul 21, 2011 at 3:41

4 Answers 4

2
$("a").click(function(e){
  e.preventDefault();
  $("targetDivSelector").load(this.href);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Do you need the content from that link into the div
0
$('a').live('click',function(e){

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

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

});

Comments

0

try this~

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

Comments

0

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());
    });
});

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.