2013-05-11 94 views
0

中的链接,我使用Superslides,它是一个全屏的jQuery滑块基本。它根据幻灯片的数量生成导航链接。动态添加ID对导航元素

对于我来说,我需要绝对定位在屏幕上的不同位置的导航链接。下面是它创造了导航代码:

<nav class="slides-pagination"> 
<a class="" href="#0"></a> 
<a class="" href="#1"></a> 
<a class="" href="#2"></a> 
<a class="current" href="#3"></a> 
</nav> 

我的问题是如何添加的ID来联系,所以我可以定位每个人,我想。或者,我可以使用“href”属性以某种方式使用jQuery选择他们,因为每个人都有不同的HREF?

$('a[href="#1"]').css(...); 

回答

1

您可以选择使用href的链接:

$('.slides-pagination a[href="#0"]') // Get the first link 
$('.slides-pagination a[href="#1"]') // Get the second link 

同样,你可以得到你想要与特定的任何链接

1

您可以使用属性选择其他答案建议,在您要添加ID的情况下,你可以使用prop perty或attr ibute方法:

$('.slides-pagination a').prop('id', function(index) { 
    return 'id' + index; // adding IDs based on the index of selected element 
}); 
+0

它应该是'$(”滑梯,分页一个 ')',而不是'$(' 滑梯-分页')',因为OP想_add ID对links_ – 2013-05-11 17:00:34