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.
- Is it possible to get the javascript to execute AND have jQuer开发者_Python百科y toggle the div?
- 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>
精彩评论