0

I need small help with jquery.

EDIT:

    echo "<li> ";
        echo $navi_menu->navi_name;
         echo "<ul>";

and the Jquery to it was,

<script type="text/javascript">
            $(document).ready(function () {
                $("#nav li:has(ul)").click(function (event) {
                    if (this == event.target) {
                        $(this).toggleClass('clicked').children('ul').slideToggle();
                        $(this).find('li:has(ul)').removeClass('clicked').find("ul").slideUp();
                        $(this).siblings().removeClass('clicked').find("ul").slideUp();
                    }
                }).addClass('has_ul');

            });
        </script>

This used to toggle up and down...now i have added a href tag in my html, instead of printing naviname(echo $navi_menu->navi_name; ) directly, i want a link to it. I need help to rewrite the jquery to accomdate a href wherever li tag comes....

   echo "<li> ";
        echo "<a class=\"click\" href=\"display_mod.php?navi_id=".$navi_menu->navi_id."\">$navi_menu->navi_name</a>";
           switch($navi_menu->navi_id) {
            case 1:
                echo "<ul>";

and the jquery to it was,

<script type="text/javascript">
            $(document).ready(function () {
                $("#nav li:has(a.click):has(ul)").click(function (event) {
                    if (this == event.target) {
                        $(this).toggleClass('clicked').children('ul').slideToggle();
                        $(this).find('li:has(a.click):has(ul)').removeClass('clicked').find("ul").slideUp();
                        $(this).siblings().removeClass('clicked').find("ul").slideUp();
                    }
                }).addClass('has_ul');

            });
        </script>

With the modifed jquery to accomdate a href tag is not working.

Here li tag is parent and ul is child and the chain continues.

(Part of the code is from cssplay.)

3 Answers 3

1

It is: $('#nav li:has(a.click)') if you want to check if the li has an a with class click as child.

Sign up to request clarification or add additional context in comments.

5 Comments

what is the exact problem now?
but how should this work at all, if your a will link to another page?
hard to judge without a complete source code. could you make a jsFiddle ?
No, it was no link I could reach.
this link works, but as i said, your links are the problem. if you click on the folder icon everything works fine, but if you click on a link you are forwarded to a new page. On this page all folders are open, but fold by clicking on the icon. I don't get what you want to achieve, sry.
1

Since the link isn't a parent or child of the ul, it looks like you just want to make it an additional constraint. Just add another has() to it?

$("#nav li:has(ul):has(a.click)").click(function (event) {

If you mean you want to now target the link itself then just use a space instead of a has method.

$("#nav li:has(ul) a.click").click(function (event) {

If this isn't what you're looking for you'll have to edit your question to clarify.

2 Comments

+1, Hi Tesserex, Thanks for ur reply. It is helpful. I have edited my question. Now i want the same toggle up and down functionality, with a href tag in it..i tried the above and till far no luck..
@lucky Which exact elements do you want to toggle up and down? The li? The a and the ul but not the li? Please clarify.
0

I think this might work for you. Give it a try.

$("#nav li:has(a.click, ul)").click(function (event) {
  //Your other statements here.
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.