jQuery how to set click on href in the div?

Posted by faya on Stack Overflow See other posts from Stack Overflow or by faya
Published on 2010-05-18T08:30:09Z Indexed on 2010/05/18 8:40 UTC
Read the original article Hit count: 193

Filed under:
|
|
|

Good day,

I want to set click event on every anchor element in my div container. Here is an example what I want to do:

---HTML---
<div id="my-container">
    <a href="page1.html">page1</a>
    <a href="page2.html">page2</a>
    <a href="page3.html">page3</a>
</div>

---- jQuery ----
$("#my-container a").click(function() {
    var link = $(this).attr("href");
    $("#my-container").load(link);
});

What I want to do is to let me handle loading event of href clicks and load it to the same container. And this is must done without id, class attributes which aren't available for that hrefs. The problem is in this: $("#my-container a"). Any help would be appreciated! Thanks

UPDATE

People doesn't seem to get right what I wanted to ask. I repeat myself again. $("#my-container a") <---- doesn't add click events on href anchors. So how I can set click event?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript