problem with jquery Toggle
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 acco开发者_JS百科mdate 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.)
It is: $('#nav li:has(a.click)')
if you want to check if the li
has an a
with class click
as child.
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.
I think this might work for you. Give it a try.
$("#nav li:has(a.click, ul)").click(function (event) {
//Your other statements here.
});
精彩评论