简体   繁体   中英

jQuery get data attribute and slidedown it's parent

I have some links (see below) where i put data-navigation attribute, and what I'm trying to do is that the data-section attribute slidesDown based on it's data-navigation parent.

HTML

<ul class="main-navbar-right">
    <li><a href="#" data-navigation="home">Home</a></li>
    <li><a href="#" data-navigation="explore">Explore</a></li>
    <li><a href="#" data-navigation="news">News</a></li>
</ul>

<section id="-navbar-home" data-section="home">
    <p>Home content</p>
</section>

<section id="-navbar-explore" data-section="explore">
    <p>Home explore</p>
</section>

<section id="-navbar-explore" data-section="news">
    <p>Home news</p>
</section>

CSS

#-navbar-home,
#-navbar-explore,
#-navbar-news {
    display: none;
}

JavaScript /jQuery (I came so far, and cannot proceed)

$(document).ready(function() {
    $('li > a').hover(function() {
        var navigation = $("a").data("navigation");
        var section = $("section").data("section");
        $(section).slideDown();
    });
});

JS Fiddle

http://jsfiddle.net/66qz2by8/

Try utilizing Attribute Equals Selector [name="value"]

var navigation = $(this).data("navigation");
var section = $("section[data-section=" + navigation + "]");
$(section).slideDown();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM