开发者

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 jQuer开发者_Python百科y 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜