-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
I coded up a mockup of the idea here. While there is overlap with .attr() I think there could still be a place for it. especially when handling data that can't be coerced to a string.
$('div').attr('data-user', {
fname: 'argyle',
lname: 'ink'
});
$('div').attr('user') // "[object Object]"
// data-user="{"fname":"ginger","lname":"chew"}"
$('div').data('user', {
fname: 'ginger',
lname: 'chew'
});
$('div').data('user') // { fname: 'ginger', lname: 'chew' }
// Needing to set `data-` like this on an object is frustrating
$('div').attr({
'data-fname': 'argyle',
'data-lname': 'ink'
'data-user-id': 1
});
// the `data-` is assumed and don't need to wrap the keys in quotes
// and converting camelCase to kebab-case is handled automatically
$('div').data({
fname: 'ginger',
lname: 'chew',
userId: 2
})The mockup handles set/get/delete, so accepting an object as the first argument like in .attr() isn't there yet.
Metadata
Metadata
Assignees
Labels
No labels