As you can see, the parent links are highlighted in blue while the child links are highlighted in grey.
I would like to make it so only the parent links show until a parent link is clicked - in which case the child elements will then show. However, I would like the child elements to show without the page having to reload.
I'm assuming I will have to use some jQuery to make this happen - which I have very little experience with.
Anyone want to get me pointed in the right direction?
@Senff, you are awesome! That's exactly what I needed, but I'm having some issues getting it to work with WordPress (not sure if you have experience with this or not).
@JeremyEnglert, you were simply forgetting to include }); at the end of the .click( ) method. Also, when using jsFiddle or CodePen you really do not need to include script tags. There is a little button at the very top (JSLINT) which will tell you any/all errors. You were able to get away with == rather then using ===. jsFiddle will always catch on that.
First off, thanks guys! You've been a big help. I think we're getting close, but something is still causing it not to work.
@JohnMotylJr I added the }); and even tried copying and pasting your code directly into the HEAD. No luck. You can see the website here:
http://www.mcfaddengavender.net/newmg/ (just pull the browser small)
I was using the tag in jsfiddle simply to show exactly how I had the code in the head.
@Senff I'll have to keep that in mind. Thanks so much for your help so far. Your code really got me going in the right direction.
This is the code I'm currently using without any luck:
For some reason, the script is not being executed. Try wrapping it in a document.ready AND move it as low as you can in the markup (try it right before the </body> tag).
I wrapped the code with the function and tried it in both the HEAD and right before and still had no luck. I'm thinking there is something causing a conflict or that jQuery isn't set up right in general.
Turns out the problem is somewhere with how WordPress is calling the jQuery script. I was using the recommended way for WP, but when I tried the standard way of calling the script everything worked great. I'm going to need to track down this issue, but that's best left for another thread.
However, with this partiucular nav, is it possible to make it so if a person clicks the parent link twice, it takes them to that page? For example, the "Results" page does not have any children and doesn't seem to have a functioning link at the moment.
Thanks again guys and sorry to make you attempt to fix an issue that was clearly my fault.
Now my next question, is it possible to make it so the jQuery only affects the mobile navigation? Currently it is also being applied to the main navigation which is causing some issues. I tried this, but had no luck:
@JeremyEnglert : FYI, not sure if this is on purpose, but when hovering over results and contact on your main nav, there is no color but you still have drop downs..
Thanks for posting this I'm using it for my mobile nav and it's working great - the only thing I need help with is making sub-menus able to function - currently if I create a submenu and give it the same class as the parent list item (.menu) it re-collapses the entire menu when you click on it. I'm not very experienced with jquery, otherwise I would think it's not that hard to do.
Hi Guys,
Currently, I'm working on a mobile navigation. here is what I have so far: http://jsfiddle.net/JeremyEnglert/9cK3X/2/
As you can see, the parent links are highlighted in blue while the child links are highlighted in grey.
I would like to make it so only the parent links show until a parent link is clicked - in which case the child elements will then show. However, I would like the child elements to show without the page having to reload.
I'm assuming I will have to use some jQuery to make this happen - which I have very little experience with.
Anyone want to get me pointed in the right direction?
Here's a quick setup: http://jsfiddle.net/senff/9cK3X/3/
@Senff, you are awesome! That's exactly what I needed, but I'm having some issues getting it to work with WordPress (not sure if you have experience with this or not).
I placed the JavaScript part from this jsFiddle into my Head: http://jsfiddle.net/9cK3X/5/
I changed $ to $j to load jQuery in no-conflict mode, but I still can't seem to get it working correctly.
Here is the website (pull your browser small for this nav): http://www.mcfaddengavender.net/newmg/
When I look at the end of your jQuery library, I see this line:
That means you should change $ to jQuery everywhere in your code, but you've replaced it with $j -- so that's why it won't work.
Try this code on your site:
Hmmm. Still no luck. Here is the code I'm using: http://jsfiddle.net/9cK3X/6/
This has me baffled.
@JeremyEnglert, you were simply forgetting to include
});at the end of the .click( ) method. Also, when using jsFiddle or CodePen you really do not need to include script tags. There is a little button at the very top (JSLINT) which will tell you any/all errors. You were able to get away with==rather then using===. jsFiddle will always catch on that.Forked Copy: http://jsfiddle.net/john_motyl/LGCXV/
On jsfiddle, there is no noConflict mode so you'll have to keep using $ there.
First off, thanks guys! You've been a big help. I think we're getting close, but something is still causing it not to work.
@JohnMotylJr I added the }); and even tried copying and pasting your code directly into the HEAD. No luck. You can see the website here: http://www.mcfaddengavender.net/newmg/ (just pull the browser small)
I was using the tag in jsfiddle simply to show exactly how I had the code in the head.
@Senff I'll have to keep that in mind. Thanks so much for your help so far. Your code really got me going in the right direction.
This is the code I'm currently using without any luck:
@JohnMotylJr Your forked copy doesn't seem to work in jsfiddle, even when I changed jQuery to $ - but I can't seem to figure out why.
@JeremyEnglert
Try this, re-wrote in CodePen so we wouldn't have unknown mysterious characters floating around in your code from jsFiddle
Promise you this works
For some reason, the script is not being executed. Try wrapping it in a document.ready AND move it as low as you can in the markup (try it right before the </body> tag).
@JeremyEnglert,
@Senff, is correct. You need to ecapsolate that bit of code in some type of anonymous function.
or
Thanks again guys.
I wrapped the code with the function and tried it in both the HEAD and right before and still had no luck. I'm thinking there is something causing a conflict or that jQuery isn't set up right in general.
Here is everything from my HEAD, including the jQuery included from @JohnMotylJr's CodePen: http://codepen.io/anon/pen/Fbcas
Turns out the problem is somewhere with how WordPress is calling the jQuery script. I was using the recommended way for WP, but when I tried the standard way of calling the script everything worked great. I'm going to need to track down this issue, but that's best left for another thread.
However, with this partiucular nav, is it possible to make it so if a person clicks the parent link twice, it takes them to that page? For example, the "Results" page does not have any children and doesn't seem to have a functioning link at the moment.
Thanks again guys and sorry to make you attempt to fix an issue that was clearly my fault.
@JohnMotylJr and @Senff, finally got this working!
Now my next question, is it possible to make it so the jQuery only affects the mobile navigation? Currently it is also being applied to the main navigation which is causing some issues. I tried this, but had no luck:
modernizer's mq function?
Solved with:
@JeremyEnglert : FYI, not sure if this is on purpose, but when hovering over results and contact on your main nav, there is no color but you still have drop downs..
Hey all -
Thanks for posting this I'm using it for my mobile nav and it's working great - the only thing I need help with is making sub-menus able to function - currently if I create a submenu and give it the same class as the parent list item (.menu) it re-collapses the entire menu when you click on it. I'm not very experienced with jquery, otherwise I would think it's not that hard to do.
Any help appreciated!