I have the following code:
$(document).ready(function(){
$("div.subtab_left li.notebook a").click(function(event) {
event.preventDefault();
return false;
});
});
but when I click the element .. it doesn't prevent the default action .. Why?
and when modifying the code to:
$(document).ready(function(){
$("div.subtab_left li.notebook a").click(function() {
e.preventDefault();
alert("asdasdad");
return false;
});
});
it stops the default action but does not alert .. I couldn't find any answer on jQuery docs.
The full code goes like this:
$(document).ready(function(){
$('#tabs div.tab').hide();
$('#tabs div.tab:first').show();
$('#tabs ul li:first').addClass('active');
$('#tabs ul li a').click(function(){
$('#tabs ul li').removeClass('active');
$(this).parent().addClass('active');
var currentTab = $(this).attr('href');
$('#tabs div.tab').hide();
$(currentTab).show();
return false;
});
$("div.subtab_left li.notebook a").click(function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
alert("asdasdad");
return false;
});
});
and the HTML structure is:
<div id="tabs">
<ul id="nav">
<li><a id="tab1" href="#tab-1"></a></li>
<li><a id="tab2" href="#tab-2"></a></li>
<li><a id="tab3" href="#tab-3"></a></li>
<li><a id="tab4" href="#tab-4"></a></li>
</ul>
<div class="tab" id="tab-1">
<script type="text/javascript">$(document).ready(function(){$("ul.produse li").hover(function () {
$("ul.produse li").removeClass('active');$(this).addClass('active');}, function () {$(this).removeClass('active');});});
</script>
<div class="subtab_left">
<ul>
<li class="notebook"><a href="#">1</a></li>
<li class="netbook"><a href="#">2</a></li>
<li class="allinone"><a href="#">2</a></li>
<li class="desktop"><a href="#">2</a></li>
<li class="procesoare"><a href="#">2</a></li>
<li class="placi_video"><a href="#">2</a></li>
<li class="hdd_desktop"><a href="#">2</a></li>
<li class="tv_plasma"><a href="#">2</a></li>
<li class="tv_lcd"><a href="#">2</a></li>
<li class="telefoane_mobile last_item"><a href="#">2</a></li>
</ul>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…