0

I'm trying to change the value of the d attribute below:

<path class="slds-progress-ring__path" id="slds-progress-ring-path-1" d="M 1 0 A 1 1 0 0 0 1 -2.4492935982947064e-16 L 0 0"></path>

I tried to change it with the setAttribute:

this.template.querySelector('#slds-progress-ring-path-1').setAttribute('d','M 1 0 A 1 1 0 0 0 -0.8090169943749475 -0.587785252292473 L 0 0');

And also by directly changing it:

this.template.querySelector('#slds-progress-ring-path-1').d = 'M 1 0 A 1 1 0 0 0 -0.8090169943749475 -0.587785252292473 L 0 0';

But got the following error:

Uncaught TypeError: Cannot read property ... of null

Please advise.

1 Answer 1

5

Don’t use ID selectors with querySelector. The IDs that you define in HTML templates may be transformed into globally unique values when the template is rendered. If you use an ID selector in JavaScript, it won’t match the transformed ID.

You can add a data attribute and query on it

Example:

Html

<path class="slds-progress-ring__path" data-id="myid" ......

JS

this.template.querySelector('path[data-id=myid]').setAttribute("d", "your value");
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.