RiyazAhmed RiyazAhmed - 3 months ago 30
HTML Question

how to change td background color after click

hello guys please help me to solve out thanks in advance
i want to display message or any kind of notification to the user like change green background color after click or message like "you click successfully"

my website image screenshot

enter image description here

here is my code



<tr>
<td>
<?php
$url=$res['url'];
$id=$res['id'];
?>
<a href="out.php?id=<?php echo $id;?>" onclick="myFunction()" target="_blank" onfocus="curTab">
<img src="admin/uploads/<?php echo $res['image']; ?>" id="click"style="width:200px;height:75px;" />
</a>
</td>
</tr>
</tbody>

Answer Source

@Ron answer is right. And if you want to use the onclick attribute like you do (it is not used in Ron's answer), you'd do:

In the html: onclick=myFunction(this)

In the js:

function myFunction(elt) {
  $(elt).parent().css("background-color","green");
}