Link to home
Start Free TrialLog in
Avatar of Mare22
Mare22

asked on

JQuery accessing attributes from click event

I am working with JQuery 1.4 and Visual Studio 2010.

I have a radio button:

<div>
     <asp:RadioButton runat="server" ID="C" Text=" ..." code="cd" />
</div>

and a click event handler:

$(document).ready(function () {
 var rb = '#<%=myID.ClientID%>';  
 $(rb).click(function () {
        var code = $(this).attr("code");
   });
});

I need to get the button's attributes, but they come in undefined.  How can this be fixed?
Thank you.
Avatar of Mare22
Mare22

ASKER

well, actually, I am running the code from my previous question:

        $(":radio", ".petsRadioButton").each(function () {
                $("form").append("<input type='radio' name='" + $(this).attr("name") + "' style='display:none' value='0' />");
        })
        $(":radio:visible", ".petsRadioButton").click(function () {
            var breedCode = $(this).attr("breedCode");
            var txt = $(this).attr("Text");
        debugger
            var $bro = $(":radio[name='" + $(this).attr("name") + "']").not(this);
            if ($bro.val() == "0") {
                $bro.val("1");
                $bro.attr("checked", false);
            }
            else {
                $bro.val("0");
                $bro.trigger("click");
            }

            var checked =  $(this).attr("checked");
            if (checked == undefined) {
                checked = false;
            }
            else {
                checked = true;
            }

        });

breedCode and txt are undefined.
Avatar of leakim971
you should be able to use : $(this).next("label").text()

Check this page, the html is the one generated by .net : http://jsfiddle.net/EAvsh/5/
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mare22

ASKER

I've actually used $(this).parent, but your comment helped.
Thank you.