Reputation: 351
Hello I wanna write a javascript function that hides an element/specfic id in my html code once the user clicks on that text. What I have right now isn't hiding the html. I'm not so good at javascript so I appreciate any help
what i have for my html:
<head> <script type="text/javascript" src="hide.js"></script> </head>
<h1 onclick = "hide(this)">[Name]</h1>
What I have for my javascript function:
function hide (el) {
el.style.visibility = "hidden";
}
Upvotes: 1
Views: 99
Reputation: 488
Change you function:
hide = function(el) {
el.style.visibility = "hidden";
}
You can test here: http://jsfiddle.net/wzte1ru9/5/
Upvotes: 0
Reputation: 762
You must pass this
to the javascript function as parameter:
<h1 onclick = "hide(this)">[Name]</h1>
this
represents the HTML DOM element.
function hide(el) {
el.style.visibility = "hidden";
}
<h1 onclick="hide(this)">[Name]</h1>
Upvotes: 1