Kanchan Bharti
Kanchan Bharti

Reputation: 57

How to label in html NOT with id?

I am working on a React App in which it requires working with tables and adding rows dynamically. I used this answer to achieve that: https://stackoverflow.com/a/54455262/13037132. I am trying to label an <input type="file" id={id} /> for styling the whole in every cell of the table. The id={id} attribute in the input element is for dynamically adding a row when an Add Row button is clicked.

I found some solution for styling this input, but it requires labelling it, needs an id attribute to link to. How can I do that, since the id is already occupied? Is there a way to link this input to a label without using the id but something else? If you want any additional data on this, please let me know.

And I am also looking for a way to add columns too just like I am adding rows using the above-stated answer. Can anyone help?

Upvotes: 0

Views: 131

Answers (1)

Farhan Ibn Wahid
Farhan Ibn Wahid

Reputation: 1012

Use a class instead of id, since multiple id with same value does not help, use a class and access that input by $(this):

$('.class_name').click(function(){
    $(this) // this will acquire the clicked/target input
})

Upvotes: 2

Related Questions