Wesley Skeen
Wesley Skeen

Reputation: 8285

jquery in an asp repeater

I have a label that holds a description and a button that will alert the description. These are housed in a repeater. So far i can get the button to alert each of the descriptions but i only want it to alert the description in its own repeater section.

I have

$(".labelInfo").each(function () {
        var desc = $(this).html();

        $(".descMore").click(function () {

            alert(desc);

        });            

    });

I know why it is doing this, but i dont know how to solve it.

Thanks to anyone who can help

Upvotes: 0

Views: 533

Answers (2)

kaps
kaps

Reputation: 478

each() iterates over jQuery object executing function for each matched element. What you did was correct except for .each(). It is executing function for each label (supposing .labelInfo is class attached to each label instance you have put in repeater. To find the description in own repeater section use closest() jquery function. This should work.

$(".descMore").click(function () {
    var desc = $(this).closest(".labelInfo").html();
    alert(desc);

});            

Upvotes: 1

ipr101
ipr101

Reputation: 24236

I'm not sure if this is what you want, but you could try this -

$(".labelInfo").each(function () {

        $(".descMore").click(function () {

            alert($(this).html());

        });            

    });

Upvotes: 0

Related Questions