Gordon
Gordon

Reputation: 1651

jquery, identify this id within this section?

I want to identify the full id tag, not sure how to do it:

    \$("div[id^='reportdate-'] input[name='radiovalue']").change(function(event) {

        var id_value = \$(this).attr('id');

        var value= \$("div[id^='reportdate-'] input[name='radiovalue']:checked").val();

        alert(value);

        alert(id_value); // NOT WORKING!!

    });

Upvotes: 0

Views: 86

Answers (2)

aziz punjani
aziz punjani

Reputation: 25776

I'm guessing you want the parent div's id and not the inputs id. You can use .parent()

$(this).parent().attr('id');

Upvotes: 1

Niels
Niels

Reputation: 49919

You are trying to get the ID of the input. You probably should use:

$(this).parent().attr("id");

If the input isn't a direct child of the id you want. You can use:

$(this).closest("[id^='reportdate-']").attr("id");

Upvotes: 5

Related Questions