The jsfiddle link is http://jsfiddle.net/PrfZy/1/
The code is:
$button = $('<button />', { text: "Some text.", name: "myButton"});
alert($button.attr("name"));
alert($button.attr("text"));
Why is the second alert “undefined”?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The valid attributes for a
<button>arename,type,valueanddisabled(which is actually considered a property and should be set and accessed viaprop()).You can create a custom attribute (which won’t validate) using the attribute setters:
http://jsfiddle.net/AlienWebguy/PrfZy/2/
The valid syntax is as follows:
http://jsfiddle.net/AlienWebguy/PrfZy/3/
Of course, the compromise of the two would be to set a valid HTML5 custom data attribute and access it via
data()http://jsfiddle.net/AlienWebguy/PrfZy/4/