2015-07-03 35 views
0

所以我試圖匹配li元素的HREF與圖片庫DIV中的DIV的ID與ID="gallery"jQuery與Href匹配div ID

alert()似乎返回正確的href屬性,但我無法設法找到匹配元素的ID並將它的CSS顯示屬性更改爲可見;

<ul> 

    <li><a class="contentUpdate" href="#logo_branding">Logo Design & Branding</a></li> 


    <li><a class="contentUpdate" href="#webdesign">Web Design</a></li> 


    <li><a class="contentUpdate" href="#mobileuidesign">Mobile UI Design</a></li> 


</ul> 


$(".contentUpdate").click(function() { 
    var href = $(this).attr("href"); 
    alert(href); 
}); 
+0

凡格畫廊 –

+0

如果您正在使用的ID? – Abhi

+0

這是繼UL –

回答

2

如果mobileuidesign是div的ID時href#mobileuidesign,然後HREF可用於id爲mobileuidesign創建元素的對象:

$(".contentUpdate").click(function() { 
    var href = $(this).attr("href"); 
    $(href).show(); 
}); 
0

您必須HREF $先輸入ID (「.contentUpdate」)。click(function(){var href = $(this).attr(「href」); $(href).attr('id');});

0

href has # too。其中div id dost。你replace更換# to nothing

$(".contentUpdate").click(function() { 
    var href = $(this).attr("href").replace("#",""); 
    alert(href); 
});