Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 选择&;更改列表项_Jquery_Html_Css - Fatal编程技术网

Jquery 选择&;更改列表项

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> </

我有许多列表项,每个都包含一个超链接。 我想做的是从每个链接获取href,并使用“点击”查询将其应用于列表项。这意味着整个li元素将是可点击的,而不仅仅是超链接

当前HTML:

<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;
});