I’m using JavaScript to split text to letters to rotate them around an anchor tag button, as route. But I have problem in the following code which appears to do nothing.
const textButtens = document.querySelectorAll('.contact');
textButtens.forEach(textButten => (
let text = textButten.querySelector('p');
text.innerHTML = text.innerHTML.split('').map((Character, index) => '<span.style="transform: rotate($(index * 12)deg)">$(character)</span>').join('');
));
.contact {
color: red;
width: 10rem;
height: 10rem;
border-radius: 50%;
display: grid;
place-items: center;
cursor: pointer;
}
.contact p {
font-size: 1rem;
font-weight: 600;
width: 10rem;
height: 10rem;
display: flex;
justify-content: center;
}
.contact p span {
position: absolute;
transform-origin: 0.3rem 5rem;
}
<a href="mailto:[email protected]" class="contact">
<p>CONTACT - SEND ME AN EMAIL</p>
</a>
By reading the docs that should work, but I can’t understand what is wrong here.
I have tried another JS code, didn’t work either.
3
Answers
The issue in your code is with the syntax of the template literals. You are using
$(index * 12)
instead of${index * 12}
to interpolate the variable. The correct syntax for interpolation is${variable}
.I also corrected the spelling of "textButtons" and added curly braces to the forEach loop.
There are multiple syntax errors in your code
Fixed syntax: