By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,046 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,046 IT Pros & Developers. It's quick & easy.

attach event problem

P: n/a
where is the problem in below code, i am not getting o/p

img=document.createElement('IMG');
img.src='Images\\add.gif';
img.style.cursor='hand';
//evnt=document.createAttribute("onmouseover");
//evnt.nodeValue="test();";
//img.addEventListener("onmouseover","test();",false );
img.attachEvent("onmouseover","test();");
td.appendChild(img);
document.body.appendChild(tbl);

Nov 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
su***************@gmail.com wrote:
where is the problem in below code, i am not getting o/p
What is 'o/p'? What is the actual problem you have?

There are many possible problems with your code, the snippet you have
posted is too brief to know what the error might be:

img=document.createElement('IMG');
Is this part of a function? If so, img should be kept local with 'var':

var img = document.createElement('IMG');

img.src='Images\\add.gif';
Two slashes in the image path? that indicates an directory with no
name, what OS allows that? Paths on the web use forward slashes:

img.src='Images/add.gif';

img.style.cursor='hand';
'hand' is not a valid CSS 2 value for the cursor property, 'pointer' is:

img.style.cursor='hand';

<URL:http://www.w3.org/TR/CSS2/ui.html#propdef-cursor>

//evnt=document.createAttribute("onmouseover");
//evnt.nodeValue="test();";
//img.addEventListener("onmouseover","test();",false );
img.attachEvent("onmouseover","test();");
It's much simpler to add events using:

img.onmouseover = test;

td.appendChild(img);
I guess 'td' is a reference to an element (probably a table cell) that
was declared/initialised elsewhere.

document.body.appendChild(tbl);


At some point was 'td' added to the document? If it's a table cell, it
must be added to a table row. There are a number of quirks regarding
adding a row to a table, might the issue be there?

Have you done appropriate feature testing for the DOM interfaces and
methods you are using elsewhere?
--
Rob
Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.