I want to change attribute names with variables. However, I can't wrap my head around how to access just the constant. In the following example, I want to change all attribute names starting with "monkey" and change them to "banana", but leave the dashes and numbers unchanged.
Change the following:
<div monkey-20="delicious" monkey-100="delicious">
To this:
<div banana-20="delicious" banana-100="delicious">
Anyone have tips?
$('div').attr('banana-20', $('div').attr('monkey-20')); $('div').removeAttr('monkey-20');?dataattribute instead. eg <div data-banana-20="delicious" data-banana-100="delicious"></div>var $div = $('div'); $div.each(function(){var t = $(this); t.attr('banana-20', (t.attr('monkey-20') || '')).removeAttr('monkey-20');});<div data-cat="monkey" data-num="20" data-val="delicious"/>to your div?