Onclick hide for single or multiple div, table,tr,.. Tags with the same function name Using Javascript

Onclick hide for single or multiple div, table,tr,.. Tags with the same function name can be done using IDs. Mostly these types of code are used for dynamic contents which are generated from Mysql and so on. Any way the code is as follows: <html>
<head>
<script>
function hide(str)
{
var elem = document.getElementById(str);
elem.style.display = 'none';
}

</script>
</head>
<body>

<h2 align="center">Using the display property of CSS</h2>

<a href="#" onclick="hide(this.id);" id="1">Here is some text which I want to hide</a>
<a href="#" onclick="hide(this.id);" id="2">Here is some text which I want to hide</a>
<a href="#" onclick="hide(this.id);" id="3">Here is some text which I want to hide</a>

</body>
</html> Note: This code also be used by putting ID s for div, table, tr and so on.. In the same time you are also able to call onclick function by setting them in a button. As you know in above I put id and I also called function in same anchor tag, if you observe. I hope this code is very useful for you. Happy coding

No comments: