I need to dynamically change the onClick event of an element. I just can't figure out how to.
I need to dynamically change the onClick event of an element. I just can't figure out how to.
Change it entirely, or just a part of it?
If it is a hard coded onclick event, all you need to do is:
Code:el.onclick=function(){whatever;};
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
In javascript, onclick is (as I wrote) all lower case:
Also, ifCode:document.getElementById(targetHeaderText).onclick = "displayFolder(16)"targetHeaderTextis the literal id of the element, it needs to be quoted within thedocument.getElementById()method, and you must assign as a function to pass parameters (also as I wrote):
Try out this demo:Code:document.getElementById('targetHeaderText').onclick = function(){displayFolder(16);};
Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> onload=function(){ document.getElementById('targetHeaderText').onclick = function(){displayFolder(16);}; } function displayFolder(n){ alert(n); } </script> </head> <body> <div id="targetHeaderText">Target Header Text</div> </body> </html>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
I need the example in VBScript as I'm keeping all the code in VBS. The HTML page is for an Outlook Folder Home Page and thus will never be viewed using Opera, Firefox!, or any browser other than a Microsoft produced one.
targetHeaderText is a variable passed into the function designating the specific <div> that will be updated.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Ended up nesting a <span> into the <div> and then using code to update the div's innerHTML property. As in...
document.getElementById(targetHeaderText).innerHTML = "<span onClick='displayFolder(" & targetFolderConstant & ")'>" & targetFolder & "</span>"
Bookmarks