0

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"));
}
1
  • 2
    Is this a typo, or do you literally have this onclick=ChkClickEvt(this); where the command is not wrapped in "? Commented Jul 30, 2014 at 12:13

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

thanks working.one more how to check null for Obj.attributes so that if it is null i can switch over to getattribute
Why do you need this check? Use always getAttribute. It's cross browser and have better support.
0

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. ;)

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.