I am trying to move an a-frame sphere using jquery attr().
I used this in the script tag(the a-sphere is already there with the id sphere.):
var x = '0 5 0';
$("#sphere").attr('position', x);
It doesn't work. Is there a different way to change it or do I have a mistake?
Use setAttribute
. More info in A-Frame docs
$("#sphere")[0].setAttribute('position', {x: 1, y: 2, z: 3});
FYI, you can also use the standard DOM querySelector instead of jQuery
document.querySelector(“#sphere”).setAttribute('position', {x: 1, y: 2, z: 3});
If still doesn’t work I recommend sharing code that people can run and debug. Glitch is great