[英]fill <li> background using href link inside it
I want to apply a class to the <li>
but i do not seem to find any way to do it. 我想对
<li>
应用一个类,但是我似乎找不到任何方法。
here is my html. 这是我的HTML。
html markup: html标记:
<nav class="topNav">
<ul>
<li id="bannera" onclick="clickOnli(href='#banner')">
<a href="#banner">Notify<img src="images/news-feed.png" class="topNavImages navNewsPic"></a>
</li>
</ul>
</nav>
jquery: jQuery的:
<script type="text/javascript">
$(document).ready(function()
{
var aChildren = $("nav li").children();
var aArray = [];
for (var i=0; i < aChildren.length; i++)
{
var aChild = aChildren[i];
var ahref = $(aChild).attr('href');
aArray.push(ahref);
}
$(window).scroll(function()
{
var windowPos = $(window).scrollTop() + $(window).height()/1.5;
var windowHeight = $(window).height();
var docHeight = $(document).height();
for (var i=0; i < aArray.length; i++)
{
var theID = aArray[i];
var divPos = $(theID).offset().top;
var divHeight = $(theID).height();
if (windowPos >= divPos)
{
$('a').removeClass("fillBlue");
$("a[href='" + theID + "']").addClass("fillBlue");
}
}
if(windowPos + windowHeight == docHeight)
{
if (!$("nav li:last-child a").hasClass("fillBlue"))
{
var navActiveCurrent = $(".fillBlue").attr("href");
$("a[href='" + navActiveCurrent + "']").removeClass("fillBlue");
$("nav li:last-child a").addClass("fillBlue");
}
}
});
});
</script>
I need to fill the li background not <a>
link/tag background. 我需要填写li背景而非
<a>
链接/标签背景。 How do i change this $("a[href='" + theID + "']").addClass("fillBlue");
我如何更改此
$("a[href='" + theID + "']").addClass("fillBlue");
so that i can fill this ID's li background. 这样我就可以填写此ID的li背景。
any help would be greatly appreciated. 任何帮助将不胜感激。
尝试这个:
$("a[href='" + theID + "']").parent().addClass("fillBlue");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.