M
Moses
Hi All,
How to avoid the execution of a function at the time of
defining.
Here i am giving the details.
I am creating the following div container through DOM.
<div id="content">
<a href="#" onclick="displayDiv('content')" > Click</a>
</div>
The Code is
var category_list = document.getElementById('category_list');
var dom_div = document.createElement('div');
dom_div.id = 'content';
var dom_link = document.createElement('a');
dom_link.href ='#';
dom_link.onclick = displayDiv();
val = document.createTextNode('Click');
dom_link.appendChild(val);
dom_div.appendChild(dom_link);
category_list.appendChild(dom_div);
The displayDiv Funcion
function displayDiv()
{
dv = document.getElementById('content'); //Here is the error.
}
The Problem is when the following script
dom_link.onclick = displayDiv('content');
is executed it is calling the function displayDiv(name)
Here we have the code
document.getElementById('content');
which throws the error.
The reason is the div container is not yet created.
What I need is the function should be called only on the click event .
It should not be called while I define it to the Click Event. (ie it
should not be called at the time of defining)
How to achieve this.
Thanks in Advance
Regards
Moses
How to avoid the execution of a function at the time of
defining.
Here i am giving the details.
I am creating the following div container through DOM.
<div id="content">
<a href="#" onclick="displayDiv('content')" > Click</a>
</div>
The Code is
var category_list = document.getElementById('category_list');
var dom_div = document.createElement('div');
dom_div.id = 'content';
var dom_link = document.createElement('a');
dom_link.href ='#';
dom_link.onclick = displayDiv();
val = document.createTextNode('Click');
dom_link.appendChild(val);
dom_div.appendChild(dom_link);
category_list.appendChild(dom_div);
The displayDiv Funcion
function displayDiv()
{
dv = document.getElementById('content'); //Here is the error.
}
The Problem is when the following script
dom_link.onclick = displayDiv('content');
is executed it is calling the function displayDiv(name)
Here we have the code
document.getElementById('content');
which throws the error.
The reason is the div container is not yet created.
What I need is the function should be called only on the click event .
It should not be called while I define it to the Click Event. (ie it
should not be called at the time of defining)
How to achieve this.
Thanks in Advance
Regards
Moses