0
Three doubts in JavaScript about className and id in innerHTML
First problem = line no : 46 Can't give class name to a variable, how can I give that .? Second and third problem = line no :51 - 63 I want to select the current row for editing and deleting , so I did give id like this , but it's not work . It will give me a error, pls check my code. How can I solve that these problems https://code.sololearn.com/WA23A15156a2/?ref=app
10 Respostas
+ 2
First problem: it is javascript variable, you can't give it class
+ 1
i is variable as well. It has only one value, not many like arrays. It won't work i[0]
+ 1
className property can only be used on elements. Not other data types. And in line 57 , I don't think i is an array of elements.
+ 1
I hate coding in a phone. Only del option is there. Its better not creating Ids and classes for simple programs.
https://code.sololearn.com/WLyoD8gwwl9C/?ref=app
0
Babanyyaz Aravind Shetty okey , thanks , you mean document.getElementById('id).className = "my_class"
But can't I assign to this in a variable .
Then can't i put the class name to that ?
Like this :
var a = document.getElementById('id)
a.className = "my_class"
How can I do that in this code .?
Because I can't assign id of td tag in a variable .
It will give as error like this
document.getElementById() is null
0
Aravind Shetty Babanyyaz okay, if I write only i without [0],[1], it don't work. ...
It will give as error , like this , it's null ..
How can I solve that. .??
0
i is just a number
you can add event to only an element .
ex : document.getElementByID('name').addEventListener('focus', focusHandler)
here focus event listener is added to tha input filed whose ID is 'name'
0
Yes you can Assign an element to a variable. And assign className property
I think you want all tr tags.. you can access table element . and then access all its children using children property.
ex: document.querySelector('table').children
0
You can only assign a class to html tag. You can't give class name to a JavaScript
0
Aravind Shetty actually I want to , when I press the 'dlt icon' i want to dlt the current tr ,
That's i want ...
Also in edit .
But , i can't assign that in a variable. ,
I tried that.
i is just a number , okay , but in this situation , i want to give separate id for each tr , like 1 , 2 , 3 , 4 etc. ..
Because of i give the 'i' as the id. .
Btw could you give me a solution. .