jQuery anchor click, "this", "e.target" - returns url
I've switched from Mootools to jQuery, because I think it has better support. I've got HTML like that:
<ul class="menuHandler">
<li class="menuTreeElement activeOpt" id="menuOpt1">
<ul id="menuOpt1Content">
<li><a href="#" class="menuOpener">Opcje</a><a href="#" class="sprite menuOpener"></a></li>
<li class="submenuElement">Opcje</li>
<li class="submenuElement">Opcje</li>
<li class="submenuElement">Opcje</li>
<li class="submenuElement">Opcje</li>
<li class="submenuElement">Opcje</li>
<li class="submenuElement">Opcje</li>
</ul>
</li>
</ul>
JS
jQuery(document).ready(function($)
{
$('.menuTreeElement .submenuElement').hide();
$('.menuHandler li.menuElement, .menuHandler li.menuTreeElement').removeClass('activeOpt');
$('.menuHandler li.menuElement, .menuHandler li.menuTreeElement').addClass('inactiveOpt');
$('.menuHandler li.menuElement a.menuOpener, .menuHandler li.menuTreeElement a.menuOpener').click(function(e){
e.preventDefault();
alert(this);
alert(this.id);
alert($(this));
alert(e.target);
alert(e.target.id);
alert($(e.target));
});
});
Results:
URL, Empty alert, [object Object], URL, Empty alert, [object Object]. I don't know what to do. Link if it'll help: http://misiur.com/CRP/admin/
I want to achieve that: 1. You click on a with class menuOpener 2. all li with class submenuElement inside same ul (in this case menuO开发者_JAVA技巧pt1Content) are showing
$('ul.menuHandler').delegate('a.menuOpener', 'click', function(ev){
//prevent follow of link
ev.preventDefault();
//create a jquery object with the anchor element
var $anchor = $(this);
//get parent li with class menuTreeElement
var $li = $anchor.closest('li');
//get its siblings and show???
$li.nextAll().show()
});
$('.menuTreeElement .menuOpener').click(function(event)
{
event.preventDefault();
$('.menuTreeElement .submenuElement').hide();
$(this).parent().find('.submenuElement').show();
return false;
});
精彩评论