How to resolve this issue - div onclick not returning id or data-id for either target or currentTarget?How to resolve this issue - div onclick not returning id or data-id for either target or currentTarget?
No matter what I try the event param will not give back the id set in the template. Here is the pertinent code...
Template
<!-- have also tried --> Javascript
handleListClick(event) { console.log('bw: id = ' + event.currentTarget.id); // output: bw: id = undefined // have also tried console.log('bw: id = ' + event.currentTarget.dataset.id); // output: bw: id = undefined //have also tried let t = event.currentTarget; let idstr = t.getAttribute("id"); console.log('bw: id = ' + idstr); // output: bw: id = null
any time I used data-id I used a dataset when trying to retrieve the value.
Also in the inspector on chrome if I look at the element, neither the id nor the data-id shows the element tree.
To resolve the issue - div onclick not returning id or data-id for either target or currentTarget, you must understand that -
The problem with your code is in the key attribute you have passed {it.value.id} whereas for data-id you have passed {it.value.Id}. Both are different as you have used capital and small i . JavaScript is case sensitive. Check the correct api name for id. Use exactly in your html code.
event.currentTarget.dataset.id or event.target.dataset.id would log the value of data-id.
Interviews
- Business Analyst Interview Questions
- DevOps Interview Questions
- AWS Interview Questions
- QA Testing Interview Questions
- Software Testing Interview Questions
- SQL Interview Questions
- Salesforce Interview Questions
- Java Interview Questions
- Hibernate Interview Questions
- Spark Interview Questions
- Vmware Interview Questions
- Data Science Interview Questions
- Digital Marketing Interview Questions
- API Testing Interview Questions
- SSAS Interview Questions
- Power BI Interview Questions
- Cloud Computing Interview Questions
- SSRS Interview Questions
- Manual Testing Interview Questions
- Social Media Interview Questions
- Performance Testing Interview Questions
- MSBI Interview Questions
- QTP Interview Questions
- Automation Testing Interview Questions
- SSIS Interview Questions
- GIT Interview Questions