for dynamically created check box when it is clicked i want to grab the attribute value.It is working in IE 8,9,10 but not working in IE 11,chrome shows function expected error
<input type=checkbox checked='checked' id='SymptomFailureCodeId' TabIndex='54' style='cursor:pointer;' onclick=ChkClickEvt(this); FailureCodeId="1" >
function ChkClickEvt(Obj) {
alert(Obj.attributes("FailureCodeId"));
}
2 Answers 2
Try using getAttribute instead:
Obj.getAttribute("FailureCodeId")
Or if you want to use attributes property don't use it as a method. It's a NamedNodeMap.
For example:
Obj.attributes["FailureCodeId"]
But be aware that this no longer supported on Firefox> 22 and many modern browsers. Read more about this at MDN
2 Comments
getAttribute. It's cross browser and have better support.A better method would be using HTML5 data-* attributes.
Markup
<input type='checkbox' id='SymptomFailureCodeId' data-FailureCodeId="1" />
JavaScript
var article = document.querySelector('#SymptomFailureCodeId'),
data = article.dataset;
console.log( data.FailureCodeId );
P.S: You would be golden with this and this
P.P.S: I am fairly sure that making up custom attributes like that is not the best practice. I am searching for further evidence to back my argument. ;)
onclick=ChkClickEvt(this);where the command is not wrapped in"?