Answer the question
In order to leave comments, you need to log in
Jquery doesn't hang handler on link in yii menu?
There is a regular menu
<?php $this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>'Home', 'url'=>array('#')),
array('label'=>'About', 'url'=>array('#about')),
array('label'=>'About2', 'url'=>array('#about2')),
),
'id'=>'top-menu',
'htmlOptions'=>array('class'=>'top-menu'),
)); ?>
<script type="text/javascript">
$(function(){
$('a').click(function(){
alert('Работает');
return false;
});
});
</script>
<a href="#about2">я ссылка не из меню</a>
then the alert works fine. $('a').click(function(){
with $('li').click(function(){
then, when you click past the link to li, the alert fires. $('li a')
and $('.top-menu li a')
and for everyone $('a').click(function(){
with $('a').live('click',function(){
Answer the question
In order to leave comments, you need to log in
preventDefault()
Read more in the documentation: api.jquery.com/event.preventdefault
Try this way
$('a').on("click", function(){
alert('Работает');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question