Jquery 选择&;更改列表项
我有许多列表项,每个都包含一个超链接。 我想做的是从每个链接获取href,并使用“点击”查询将其应用于列表项。这意味着整个li元素将是可点击的,而不仅仅是超链接 当前HTML:Jquery 选择&;更改列表项,jquery,html,css,Jquery,Html,Css,我有许多列表项,每个都包含一个超链接。 我想做的是从每个链接获取href,并使用“点击”查询将其应用于列表项。这意味着整个li元素将是可点击的,而不仅仅是超链接 当前HTML: <ul class="menusidecourse"> <li><a href="LINK1" >Item 1</a></li> <li><a href="LINK2" >Item 2</a></li> </
<ul class="menusidecourse">
<li><a href="LINK1" >Item 1</a></li>
<li><a href="LINK2" >Item 2</a></li>
</ul>
谢谢你的关注
注:
必须这样做,因为菜单是由joomla动态生成的。如下所示:
// add a click handler to the li element
$('.menusidecourse li').click(function(){
// find the a element inside this li and get it's href
var link = $('a', this).attr("href");
// navigate to the retrieved href
window.location.href = link;
});
像这样:
// add a click handler to the li element
$('.menusidecourse li').click(function(){
// find the a element inside this li and get it's href
var link = $('a', this).attr("href");
// navigate to the retrieved href
window.location.href = link;
});
// add a click handler to the li element
$('.menusidecourse li').click(function(){
// find the a element inside this li and get it's href
var link = $('a', this).attr("href");
// navigate to the retrieved href
window.location.href = link;
});