Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

is it possible for a stylesheet to assign an onclick event handler to an element. I have a bunch
buttons that use same js event handler. Trying to minimize server respond time.

Thanks,

-ren
Posted

1 solution

This is done not through style sheet but Javascript and DOM. Using your body element, you can call some Javascript to set up all other event handlers programmatically:

XML
<html
    <head>
        <title>???</title>
        <script type="text/javascript"><!--
            function OnLoadHandler() {
                   /* setup all handlers here */
               }
        --></script>
    </head>
</body onload="Javascript:OnLoadHandler()">
    <!-- your inner html -->
</html>


This is just a skeleton.

Another option is to auto-generate all HTML content with some server-side technology. You can mix auto-generated context with HTML code using ASP.NET, JSP, PHP…

—SA
 
Share this answer
 
v5
Comments
Sergey Alexandrovich Kryukov 15-Mar-11 1:09am    
Albin, thank you for the spelling fix.
--SA
Espen Harlinn 15-Mar-11 12:22pm    
Good points, my 5
Sergey Alexandrovich Kryukov 15-Mar-11 13:14pm    
Thank you.
--SA
Member 2542530 15-Mar-11 23:29pm    
Sa,

thanks for the comment. I kind of understand. Could you show a simple example? I am familar with on load event just not sure how to attach event to button.

Thanks,
-ren

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900