Get DOM id attribute from current element

Hey there! How do I get the id attribute of the current element in an inline function, similar to how it's possible in basic HTML? This code snippet works in basic HTML:
<button id="hi" onclick="console.log(this.id)">Click me</button>
<button id="hi" onclick="console.log(this.id)">Click me</button>
How would I achieve this with tsx in SolidJS?
<button
onClick={() => {
console.log(this.id); //this doesn't work because "self" is not defined.
}}
>
Click me
</button>
<button
onClick={() => {
console.log(this.id); //this doesn't work because "self" is not defined.
}}
>
Click me
</button>
This seems like a really simple question, but I kinda struggled with finding a solution, other then wrapping it in a component and getting/managing the id like that. Thanks for the help! =)
2 Replies
ElitoGame
ElitoGameOP13mo ago
Thanks =)
mdynnl
mdynnl13mo ago
it should work with regular <button onClick={function(e) { console.log(this === e.currentTarget) }}>
Want results from more Discord servers?
Add your server