开发者

jQuery Javascript removing attribute from filtered item

开发者 https://www.devze.com 2022-12-21 23:29 出处:网络
I have a treeview menu with variable levels. Only element on last level is clickable, the rest should have links \"#\". By default level 2 and 3 have links (links are created dynamically so I can\'t a

I have a treeview menu with variable levels. Only element on last level is clickable, the rest should have links "#". By default level 2 and 3 have links (links are created dynamically so I can't add them by jQ). If li level is 3, I need to change href for level 2 to "#" but I can't get it working :/

<ul id="Menu">
<li>
    <span id="primary">
        <h1>
            <a href="#">Torby</a>
        </h1>
    </span>
    <ul>
        <li>
    开发者_如何学JAVA        <span id="secondary">
                <h2>
                    <a href="/category/category/bags_/">Torby</a>
                </h2>
            </span>
            <ul>
                <li>
                    <h3>
                        <a href="/category/category/shoulderbag/">Na Ramię</a>
                    </h3>
                </li>
            </ul>
        </li>
    </ul>
</li>

h2 href is what I'm after . I've tried sth like this :

$("Menu ul").has("h3"){
    $(this).find("#secondary h2 a").attr("href","#");
};

This is how it looks :

http://img707.imageshack.us/img707/2855/menule.jpg


Your $("Categories ul") is missing, it seems, an ID sign (#).

Also, you should try to write standard HTML. Don't put H2s in spans. You can use a div there.

..Also, don't you want something more like

$(this).find("#secondary h2 a").attr("href", "#");

?

0

精彩评论

暂无评论...
验证码 换一张
取 消