+ 11
How can I change the background-color of <td> whenever I click on that?
17 Réponses
+ 10
[...document.getElementsByTagName("td")].forEach(td => td.addEventListener("click", e => e.target.style.background= "red"))
https://code.sololearn.com/WV806eog003Y/?ref=app
+ 9
Calviղ nice bro but could you please simplify the code
I am having trouble in understanding jquery code
+ 7
<td onclick="colour ()" id="td">
Some text
</td>
<script>
function colour (){
document.getElementById('td').style. backgroundColor='red';}
</script>
+ 7
Calviղ I mean ECMAScript6
+ 7
marjel101 as you wish
+ 6
on Click change style :color=red
+ 3
Shreyansh It is not jQuery codes, it's javascript code. Please restudy your javascript course.
+ 3
Shreyansh The code of Calviղ uses arrow functions, which I am also not very used to.
Maybe you understand it better in this form:
https://code.sololearn.com/WnNb5I2oi8Yl/?ref=app
+ 3
marjel101 Thanks for showing the simple way of the javascript code.
+ 3
$(function(){
$("td").on("click", function(){
$(this).css({"color": "red"});
});
});
+ 2
CSS:
td:hover {
background-color: red;
}
+ 2
td:focus{ background : red; }
+ 1
use js DOM
+ 1
use js DOM
0
td color
0
can anyone help me?
https://www.sololearn.com/discuss/2092982/?ref=app