I am doing this with jQuery :
@xmlOut = $('<rules />')
@xmlOut.attr('xsi:schemaLocation','test')
I get this :
<rules xsi:schemalocation='test'></rules>
The "L" is not uppercase anymore...
Kevin's answer is incorrect, .setAttribute() will change the attribute name to lowercase.
Instead, use element.setAttributeNS() with an empty string for the first parameter.
@xmlOut.get(0).setAttributeNS('', 'xsi:schemaLocation','test')
https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttributeNS
There is a ticket http://bugs.jquery.com/ticket/11166
Alternatively, you can add attribute hook (with lowercase name) to jQuery in order to use desired setter method. For example:
$.attrHooks['viewbox'] = {
set: function(elem, value, name) {
elem.setAttributeNS(null, 'viewBox', value + '');
return value;
}
};
Then you can set the attribute case sensitive with .attr():
$('svg').attr('viewBox', '0 0 100 100');
Try using plain Javascript's setAttribute
which is not case sensitive.
@xmlOut.get(0).setAttribute('xsi:schemLocation', 'test');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With