Issue
I'm trying to add an attribute to an angularJs element from a directive like this:
element.attr('startOffset', val);
But when I check the element, the attribute added is 'startoffset' where the 'o' is not a capital letter.
Is there any way to add an attribute to an element and keep the case of the word intact?
Thanks
Solution
If you set an attribute using jqliteWrapper .attr
or even with direct DOM operation .setAttribute
it will lowercase the attribute name, before attaching to the element.
When called on an HTML element in an HTML document, setAttribute lower-cases its attribute name argument.
Since you are using SVG try direct operation with setAttribute
, however setting attributes preserve their cases with SVG, not sure if jquery does any transformations internally.
element[0].setAttribute('startOffset', val);
Confirmed that it is jquery inclusion before angular which causes it not to preserve the attribute name casing while setting it via .attr
, but if you do not include jquery and angular falls back to jqLite it will set the attribute name as is, so that will work (along with attrs.$set
) with SVG as well apart from the direct DOM operation.
Answered By - PSL
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.