0

I'm building a react app and I have a few on page anchors. I've made divs with the proper IDs and the traditional anchor tag with a hash matching those IDs.

How can I find the same div ID when I click on the anchor with the matching hash? Right now I'm using the event to pass into my onClick function.

3
  • 1
    Please post your code. Commented Jan 17, 2019 at 20:21
  • What is a click on the <a> supposed to do? Scroll to the div? This sounds like an XY problem. Commented Jan 17, 2019 at 20:21
  • The click on the anchor will scroll to that div. Commented Jan 17, 2019 at 20:34

1 Answer 1

1

It sounds like you just need to provide the id in your onClick handler in the jsx.

<a onClick={() => this.handleClick(id)}>{id}</a>
Sign up to request clarification or add additional context in comments.

2 Comments

What if the my markup looks like this: <a onClick={() => this.handleClick(id)}>Some Text</a>
That should work find so long as the id variable is available

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.