- 1
<td class="line-number" value="1772"></td>
please my question solve please <td class="line-number" value="1772"></td>
3 ответов
+ 2
jai baba di jai baba di what is your question ?
0
what's your question
0
only input/form fields element have a value attribute... to store user defined attribute you must use data-* attributes to be valid html:
<td class="line-number" data-value="1772"></td>
doing so, you can access the value stored in your user defined attribute through JS by using the .dataset object property:
onload = () => {
let ln_num = document.querySelectorAll(".line-number");
for (let ln of ln_num) {
ln.onclick = handleLineClick;
}
function handleLineClick() {
console.log("line number",this.dataset.value,"was clicked");
}
};
https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/data-*
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/dataset