Ticket #5400 (closed bug: invalid)
attr(name), property of an object with dash/hyphen in name returns undefined
| Reported by: | kivanov | Owned by: | john |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | selector | Version: | 1.3.2 |
| Keywords: | attr dash hyphen | Cc: | |
| Blocking: | Blocked by: |
Description
When using attr(name) to get value of parameter for given object, if the name contains any dash/hyphen followed by letter [a-z] it fails on the conversion to upper case by removing the dash/hyphen.
The code that does that is in the attr function:
name = name.replace(/-([a-z])/ig, function(all, letter){
return letter.toUpperCase();
});
Change History
comment:2 Changed 4 years ago by kivanov
var _object = new Object(); var _property = "my-property"; _object[_property] = "test"; console.log(_object[_property]); console.log($(_object).attr(_property)); console.log(_object[_property] == $(_object).attr(_property));
Both ways should return the same results, but they are not. If the property name does not contain "-" followed by [a-z] it works fine.
comment:3 Changed 4 years ago by kivanov
Any progress on this bug? The fix seams easy, just remove the regular expression replacement within the attr function, shown above. Unless that is necessary for some internal use.
comment:5 Changed 3 years ago by rwaldron
- Priority changed from major to low
- Status changed from new to closed
- Resolution set to invalid
- Milestone 1.3.2 deleted
.attr() is designed for use with element attributes and properties, http://api.jquery.com/attr/
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Can you provide an example?