0

I have some checkboxs with the same name but each has a unique value. I want that on any click on specific checkbox to get the unique value of the cpecific clicked checkbox.

@foreach (var itert in Model.collec)
            {

                            @Html.CheckBox("chkResend",
                            new { @value = Html.Encode(itert.EventNumber), 
@class = "myclass" })

 };

the jquery is:

$(document).ready(function () {    
    $(".myclass").click(function () {
        alert($(".myclass").attr("value"));
    });

});

all the time I get the value of the first checkbox...

1 Answer 1

1

Use this keyword

$(document).ready(function () {
    $(".myclass").click(function () {
        alert(this.value); //this refers to the current element clicked
        // or alert($(this).attr("value"));
        // or alert($(this).val());
    });
});
Sign up to request clarification or add additional context in comments.

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.