简体   繁体   中英

Can a link have both an onclick jquery and javascript event?

I have a link that jQuery listens to, and if clicked it will toggle another div. The link also has an onclick javascript action. When I click the link, the div I want to toggle shows, but the javascript doesn't execute.

  1. Is it possible to get the javascript to execute AND have jQuery toggle the div?
  2. If so what would I put in the jQuery code to allow the link to execute the onclick javascript action?

jQuery script

$(function() {
  $('#links a').live('click', function() {
  $("#showall").toggle('slow');
  });
});

my link

<div id ="links">
  <a href="some javascript" onclick="javascript">Play</a>
</div>

for me the following is working in Chrome, Firefox and IE. Both pure Javascript (onclick) and jQuery click() get executed.

<html>                                                                  
 <head>                                                                  
 <script type="text/javascript" src="jquery-1.4.4.js"></script>          
 <script type="text/javascript">                                         
   $(document).ready(function() {
        $('a').click(function() {
            $('div').toggle();
        });
   });                                    
 </script>                                                               
 </head>                                                                 
 <body>                                                                  
    <a href="#" onclick="alert('original onclick')">Click me</a>
    <div>
        Some div content...
    </div>
 </body>                                                                 
 </html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM